'After Angular 13 Upgrade, Jasmine Unit Test Fails - Expected one matching request for criteria "Match method: POST, URL: api/x/x-search", found none
After upgrading to Angular 13 from 12, some of the Unit Tests started failing:
Error: Expected one matching request for criteria "Match method: POST, URL: api/x/x-search", found none.
This is the mock
async function mockXSearch(error?: string) {
const req = httpMock.expectOne({ method: 'POST', url: 'api/x/x-search' });
if (error) {
req.flush({ title: errorMsg }, { status: 500, statusText: 'Internal Server Error' });
} else {
req.flush(mockX, { status: 200, statusText: 'OK' });
}
return page.whenStable();
}
And this is the service:
searchX(someData: string, foo: number, xType: XType) {
return this.http.post<X[]>(`${this.baseUrl}/x-search`, { someData, foo, xType });
}
I already checked that the Mock Url and the Service Url make match. Any idea ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|