Testing Angular Applications
Writing automated tests for your applications is just as important as writing the application code. Many developers don’t like to write tests or skip them altogether because they feel it’s too time-consuming, but as your applications and workspace grow, having automated tests becomes ever more critical. When working on an extensive application, the chances are significant that your changes will impact many things throughout the application. Small changes can affect many things, which becomes even more apparent when you’re making changes in a library used in many applications. You’ll often find yourself in a scenario where you make changes and don’t even know every application surface your changes will impact. Because you don’t want to break features, you don’t want to work on or manually test the entire workspace each time you make a change; you need automated tests that can test all affected code for you. Automated tests will help you look at your code differently; they can help you write better, more sturdy code. Automated tests will also catch bugs at an early stage and should give you the confidence to safely release code changes to production once all tests have successfully passed.
This chapter will dive into different types of automated tests and their purpose within your Angular applications. Next, you will dive deeper into the topic of unit testing and get some hands-on experience by writing unit tests for our Nx monorepo using Jest. Lastly, you will learn more about end-to-end testing and gain some experience writing end-to-end tests using Cypress. By the end of this chapter, you will understand why you need automated tests and how to write them for your Angular applications.
This chapter will cover the following topics:
- Different types of application testing
- Unit testing of Angular applications using Jest
- End-to-end testing of Angular applications using Cypress