I keep getting the following errors when running unit tests
Error: StaticInjectorError(DynamicTestModule)[ApiService -> HttpClient]:
StaticInjectorErro
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.