I've found several answers to this problem, but all of them involve having parameters and not including them on the call. But my case is different because I do not have parameters.
According to all the material, I have consulted, I cannot find what I'm doing wrong.
Basically, it is this:
in the service I'm testing, I have a call like this:
public getData(): Observable<string[][]> {
const url = `${this.config.baseUrl}/data/`;
return this.http.get<string[][]>(url);
}
in providers of the spec file
{ provide: ConfigService, useValue: { baseUrl: '/base-url', tokenAuth: true } },
and
httpMock = TestBed.inject(HttpTestingController);
service = TestBed.inject(DataService);
and the test
it('should return the values of data when calling the API,' done => {
const mockValue: [['data1','data2'],['data3','data4'],['data5','data6']];
const sub = service.getData().subscribe(
value => {
expect(value).toHaveLength(3);
httpMock.verify();
done();
},
error => {
throw error;
},
);
subs.add(sub);
httpMock.expectOne('/base-url/data').flush(mockValue);
});
But when I ran the test, I received the following:
Expected one matching request for criteria "Match URL: /base-url/data/", found none.