Introducing Unit Tests in Angular
Learn about the tools provided by the Angular framework and Angular CLI to write unit tests and test a component.
We'll cover the following...
We familiarized ourselves with unit testing and its general concepts, such as test suites, test specs, and assertions. It is now time to venture into unit testing with Angular. Before we start writing tests for Angular, though, let’s have a look at the tooling that the Angular framework and Angular CLI provide us with to make unit testing a pleasant experience:
Jasmine: We have already learned that this is the testing framework.
Karma: The test runner for running our unit tests.
Angular testing utilities: A set of helper methods that assist us in setting up our unit tests and writing our assertions in the context of the Angular framework.
When we use the Angular CLI, we do not have to do anything to configure Jasmine and Karma in an Angular application. Unit testing works out of the box as soon as we create a new Angular CLI project. Most of the time, we will interact with the Angular testing utilities.
Concepts that help in Angular testing
Angular testing utilities help us create a testing environment that makes writing tests for our Angular artifacts easy. It consists of the TestBed
class and various helper methods that can be found under the @angular/core/testing
namespace. As this chapter progresses, ...