'Angular http test not finding request

I'm doing a Jasmine test mocking a HTTP request, but I'm getting the following error:

Failed: Expected one matching request for criteria "Match URL: https://myurl.net/api/v2/OperationalAreas/1/Equipments?PageNumber=1&PageSize=10&NeedPaging=TRUE&Filter=id:%3C%3E:6.", found none. Requests received are: GET https://myurl.net/api/v2/OperationalAreas/1/Equipments?PageNumber=1&PageSize=10&NeedPaging=TRUE&Filter=id:%3C%3E:6.

As you can see, the URL is identical, but it displays an error anyway.

The test is something like that:

it(
    'should do my test',
    waitForAsync(() => {
      spyOn(service, 'allTypes').and.returnValue(getAllTypesMock);

      service.getFromPage(1).subscribe((page) => {
        expect(page.items.length).toEqual(9);
      });

      service.allTypes().subscribe(() => {
        const req = httpMock.expectOne(
          `${environment.myUrl}api/v2/OperationalAreas/1/Equipments?PageNumber=1&PageSize=10&NeedPaging=TRUE&Filter=id:%3C%3E:6.`
        );
        expect(req.request.method).toBe('GET');
        req.flush(getPage1TenResponseDTO);
      });
    })
  );

Any ideas?



Solution 1:[1]

The solution was quite simple, actually.

I just put an extra dot (.) at the end of the url. And, as the error message itself has a period, that confused me.

So I just remove the dot and everything just worked fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Artur Quirino