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.

8.1.1 Prerequisites

 
 
 
 

8.1.2 What is a unit test?

 
 
 

8.1.3 Why do we want unit tests?

 
 
 

8.2 Configuring a testing environment

 
 

8.2.1 Choosing a test runner

 

8.2.2 Setting up the test runner

 
 
 

8.2.3 Installing third-party tools

 
 
 

8.3 Running Angular unit tests

 
 
 

8.3.1 What do unit tests look like?

 

8.3.2 Providing mock dependencies

 

8.3.3 Testing components

 
 

8.3.4 Testing services

 
 
 

8.3.5 Testing signals

 
 

8.4 Powers of AI with Angular unit tests

 
 
 

8.4.1 Unit testing Angular applications with ChatGPT

 
 
 

8.4.2 Unit testing Angular applications with GitHub Copilot

 
 
 

8.5 Future of unit testing in Angular

 
 
 
 

8.6 Exercises for the reader

 
 

8.7 Summary

 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest