mardi 12 janvier 2021

Angular httpTestingController.expectOne throws even though httpClient.get was called

I have this simple function inside a service:

getReports(url: string): Observable<Report[]> {
    return this.http.get<Report[]>(url);
}

My test is as follows:

  it(`should call http request`, function() {
    spyOn(httpClient, 'get');
    const fakeUrl = 'https://reports.url/';
    service.getReports(fakeUrl);

    expect(httpClient.get).toHaveBeenCalledWith(fakeUrl);
    const req = httpTestingController.expectOne(fakeUrl);
  });

The first expectation passes (so httpClient.get was called with the fakeUrl, but the controller's expectOne failed:

Expected one matching request for criteria "Match URL: https://reportss.url/", found none.

Any idea why angular's testing controller doesn't recognize my call?

Thanks!

Aucun commentaire:

Enregistrer un commentaire