Providers

You'll note that the number of errors didn't go down. Instead, AppComponent and CurrentWeatherComponent are failing to be created due to a missing provider for WeatherService. So, let's add the provider for WeatherService to the spec files for both components.

  1. Provide the WeatherService in the declarations in app.component.spec.ts
  2. Apply the same code change in current-weather.component.spec.ts, as shown:
src/app/app.component.spec.tssrc/app/current-weather/current-weather.component.spec.ts...  beforeEach(    async(() => {      TestBed.configureTestingModule({        declarations: [...],        providers: [WeatherService],        ...
You may wonder why AppComponent is needing a provider, since the component constructor is not injected with the WeatherService ...

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.