8 Unit testing in Modern Angular
This chapter covers
- Understanding what unit tests are and how they work in Angular
- Setting up a unit testing environment
- Writing unit tests for Angular building blocks
- Unit testing classes that use the “inject” function
- Unit testing signals
- Third-party tools that facilitate unit testing of Angular applications
- AI tools to assist with unit testing
In previous chapters, we learned about all the modern code-level tools that Angular now provides out of the box to make developing large front-end applications as seamless as possible. All of those tools were confined to the code that we write itself, helping to solve business requirement-related issues. But what about building our applications, developer experience, deployment, search engine optimizations, and so on? Now it is time we explore all those topics. However, before we can actually deploy our beautiful HRMS application, we need to ensure it works properly and is reasonably maintainable (as in “will not break easily when developers add new changes”). And this is precisely what this chapter is about: unit testing.
8.1 Unit testing: the what and the why
Before we begin, let’s briefly discuss unit testing in more general terms, the reasons why we need it, and how to achieve it. First, let’s talk about the stuff we need to know before diving into the specifics.