Unit Testing in Angular

The hard work of the previous chapters has materialized into a working application we can be proud of. But how can we ensure a painless maintainability in the future? A comprehensive automated testing layer will become our lifeline once our application begins to scale up and we have to mitigate the impact of bugs, caused by new functionalities colliding with the already existing ones.

Testing (and more specifically, unit testing) is meant to be carried out by the developer as the project is being developed. However, we will cover all the intricacies of testing Angular modules in brief in this chapter, now that the project is at a mature stage.

In this chapter, you will see how to implement testing tools to perform proper unit testing of your application classes and components.

In this chapter, we will:

  • Look at the importance of testing and, more specifically, unit testing
  • Build a test spec testing a pipe
  • Design unit tests for components, with or without dependencies
  • Put our routes to the test
  • Implement tests for services, mocking dependencies, and stubs
  • Intercept XHR requests and provide mocked responses for refined control
  • Discover how to test directives as components with no view
  • Introduce other concepts and tools such as Karma, code coverage tools,
    and end-to-end (E2E) testing
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset