29 Angular unit testing

 

This chapter covers

  • Creating and performing unit tests in Angular projects
  • Isolating components and directives for unit testing
  • Testing Angular features, such as input and output properties
  • Testing the HTML content generated by components

In this chapter, I describe the tools that Angular provides for unit testing components and directives. Some Angular building blocks, such as pipes and services, can be readily tested in isolation using the basic testing tools that I set up at the start of the chapter. Components (and, to a lesser extent, directives) have complex interactions with their host elements and with their template content and require special features. Table 29.1 puts Angular unit testing in context.

29.1 Preparing the example project

29.2 Running a simple unit test

29.3 Working with Jasmine

29.4 Testing an Angular component

29.4.1 Working with the TestBed class

29.4.2 Testing data bindings

29.4.3 Testing a component with an external template

29.4.4 Testing component events

29.4.5 Testing output properties

29.4.6 Testing input properties

29.5 Testing an Angular directive

29.6 Summary