I am starting a new angular project with the CLI and am running into a no provider for HttpClient error.
I have added HttpClientModule to m
An easier way is to provide it globally....Import the following into app.module.ts like so:
import { HttpModule } from '@angular/http'
import { HttpClient, HttpClientModule } from '@angular/common/http';
and declare it in imports:
imports: [
HttpModule,
HttpClientModule, ...
]
In your test
TestBed.configureTestingModule({
providers: [FlexSearchService, HttpClientModule]
});
It should be
TestBed.configureTestingModule({
imports: [HttpClientModule],
providers: [FlexSearchService]
});
or even better (if you want to mock request):
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [FlexSearchService]
});
Import HttpClientTestingModule.
In your test:
import { HttpClientTestingModule } from '@angular/common/http/testing';
and in the configureTestingModule of your test, do the following:
TestBed.configureTestingModule({
imports: [ HttpClientTestingModule ],
})
.compileComponents();
I've noticed this issue when I was trying to link my angular library locally within my project using the npm link.
Downloading the library from the repository solved my issue.
For this you have to import the following:
import { HttpClientTestingModule } from '@angular/common/http/testing';
And for the spec file in the configureTestingModule of your test, do the following:
TestBed.configureTestingModule({
imports: [ HttpClientTestingModule ],
})
.compileComponents();