The anatomy of a unit test
There are many different ways to test a piece of code. Ιn this chapter, we will look at the anatomy of a test—the different parts that it's made of. To test any code, we need two things: a framework for writing the test and a runner to run it on. The test framework should provide utility functions for building test suites, containing one or several test specs each. As a result, unit testing involves the following concepts:
- Test suite: A suite that creates a logical grouping for a bunch of tests. A suite, for example, can contain all the tests for a specific feature.
- Test spec: The actual unit test.
We are going to use Jasmine, a popular test framework, which is also used by default in Angular CLI projects. Here is how a unit test looks in Jasmine:
describe('Calculator', () => { it('should add two numbers', () => { &...