Chapter 14. Testing Angular applications

 

This chapter covers

  • Using the Jasmine framework for unit testing
  • Identifying the main artifacts from the Angular testing library
  • Testing services, components, and the router
  • Running unit tests against web browsers with the Karma test runner
  • End-to-end testing with the Protractor framework

To ensure that your software has no bugs, you need to test it. Even if your application has no bugs today, it may have them tomorrow, after you modify the existing code or introduce new code. Even if you don’t change the code in a particular module, it may stop working properly as a result of changes in another module or in the runtime environment. Your application code has to be retested regularly, and that process should be automated. You should prepare test scripts and start running them as early as possible in your development cycle.

This chapter covers two main types of testing for the frontend of web apps:

  • Unit testingAsserts that a small unit of code accepts the expected input data and returns the expected result. Unit testing is about testing isolated pieces of code, especially public interfaces.
  • End-to-end testingAsserts that the entire application works as end users expect and that all application parts properly interact with each other.

14.1. Unit testing

14.2. Running Jasmine scripts with Karma

14.3. Using the Angular testing library

14.4. End-to-end testing with Protractor

14.5. Hands-on: Adding an E2E test to ngAuction

Summary