title: Angular 5 service failing to pass unit tests with (NullInjectorError: No provider for HttpClient!)
body: <p>I keep getting the following errors when running unit tests</p>
  
  <pre><code>Error: StaticInjectorError(DynamicTestModule)[ApiService -&gt; HttpClient]: 
        StaticInjectorError(Platform: core)[ApiService -&gt; HttpClient]: 
          NullInjectorError: No provider for HttpClient!
  </code></pre>
  
  <p><strong>api.service.ts</strong></p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { HttpClient } from '@angular/common/http';
  
  @Injectable()
  export class ApiService {
  
    constructor(private http: HttpClient) { }
    url = './assets/data.json';
  
    get() {
      return this.http.get(this.url);
    }
  }
  </code></pre>
  
  <p><strong>api.service.spec.ts</strong></p>
  
  <pre><code>import { TestBed, inject } from '@angular/core/testing';
  import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
  
  import { ApiService } from './api.service';
  
  describe('ApiService', () =&gt; {
    beforeEach(() =&gt; {
      TestBed.configureTestingModule({
        imports: [
          HttpClientTestingModule,
        ],
        providers: [
          ApiService,
        ],
      });
    });
  
    it('should get users', inject([HttpTestingController, ApiService],
        (httpMock: HttpTestingController, apiService: ApiService) =&gt; {
          expect(apiService).toBeTruthy();
        }
      )
    );
  });
  </code></pre>
  
  <p>I don't understand what is going wrong as I have included HttpClient into api.service.ts, the service works in the browser.</p>
  
  <p>This is directly called in a component called MapComponent, and that is called inside HomeComponent.</p>
  
  <pre><code>Chrome 63.0.3239 (Mac OS X 10.13.3) HomeComponent expect opened to be false FAILED
      Error: StaticInjectorError(DynamicTestModule)[ApiService -&gt; HttpClient]: 
        StaticInjectorError(Platform: core)[ApiService -&gt; HttpClient]: 
          NullInjectorError: No provider for HttpClient!
  </code></pre>