2 Creating your first tests
This chapter covers
- Writing basic unit tests using Jasmine
- Using
beforeEach
,afterEach
,it
,describe
, and matcher functions - Testing classes
Now that you understand the basics of Angular testing, you’ll get started writing tests. Before you continue, follow the project setup instructions in appendix A to install the sample project along with the necessary tools: the Angular CLI, Jasmine, Protractor, and Karma. You’ll use the sample project throughout the book.
After you get the sample project up and running, you’ll start writing basic tests using Jasmine, the behavior-driven JavaScript testing framework that you’ll use throughout the book. We won’t talk about any of the testing modules that come with Angular in this chapter. We’ll save those for chapter 3 and the rest of the book.
We want to cover testing without the Angular test modules because at times you won’t need help from Angular itself. For example, you might have a pipe that transforms dates or a function that performs a calculation that needs to be tested, and you could test them without any help from the Angular test modules. If you aren’t familiar with pipes, don’t fret. All you need to know for this example is that it’s an Angular utility that can be used to transform data. Chapter 5 is dedicated to pipes.