Imports

You still have errors remaining. Let's start by fixing the errors with the WeatherService error first, since it's a dependency of other components. The test is reporting a missing provider for HttpClient. However, we don't want our unit test to make calls over HTTP, so we shouldn't provide the HttpClient, like we did in the previous section. Angular provides a test double for HttpClient named HttpClientTestingModule. In order to leverage it, you must import it, and it will then be automatically provided to the service for you.

Import HttpClientTestingModule below the providers:

src/app/weather/weather.service.spec.tsimport { HttpClientTestingModule } from '@angular/common/http/testing' ...describe('WeatherService', () => { beforeEach(() ...

Get Angular 6 for Enterprise-Ready Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.