Jasmine specs
There are two failing unit tests. In Jasmine lingo, unit tests are called specs, implemented by the it function; it functions are organized under the describe functions that contains helper methods that can execute before or after each test and handle the overall configuration needs of specs. Your app has five specs that have been generated for you, and two of them are now failing.
The first is AppComponent should have as title 'app'; however, we deleted this property from AppComponent, because we are not using it. In this rare case, we need to do this:
- Delete the should have as title 'app' unit test.
The error message is descriptive enough to let you know what test is failing quickly. This happens, because the description provided to the describe function is 'AppComponent' , and the description provided to the it function is 'should have as title "app"'. Jasmine then appends any parent object's description to the description of the spec. As you write new tests, it is up to you to maintain readable descriptions for your specs.
The next error, AppComponent should render title in a h1 tag, is one that we must fix. We render the words LocalCast Weather in the h1 tag now.
- Update the should render title in a h1 tag test as shown:
src/app/app.component.spec.ts
...
it(
'should render title in a h1 tag',
...
expect(compiled.querySelector('h1').textContent).toContain('LocalCast Weather')
...
All unit tests are now successfully passing. We should be performing atomic commits, so let's commit the code changes.
- Commit your code changes.
In order to achieve effective unit test coverage, you should focus on testing the correctness of functions that contain business logic. This means that you should pay extra attention to adhering to the Single Responsibility and Open/Closed Principles, the S and O in SOLID principles.