Angular 5 service failing to pass unit tests with (NullInjectorError: No provider for HttpClient!)

The reason for "NullInjectorError: No provider for HttpClient!" are unresolved dependencies. In this case the lack of a HttpClientModule.

In your .service.spec.ts file add

  imports: [
        HttpClientTestingModule,
    ],

You might notice that I wrote HttpClientTestingModule instead of HttpClientModule. The reason is that we don’t want to send actual http requests, but rather use a Mock API of the test framework.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)