fix(common): http/testing expectOne lists the received requests if no matches (#27005)
Fixes #18013 Previously it was hard to debug an `expectOne` if the request had no match, as the error message was: Expected one matching request for criteria "Match URL: /some-url?query=hello", found none. This commit adds a bit more info to the error, by listing the actual requests received: Expected one matching request for criteria "Match URL: /some-url?query=hello", found none. Requests received are: POST /some-url?query=world. PR Close #27005
This commit is contained in:
@ -90,7 +90,19 @@ export class HttpClientTestingBackend implements HttpBackend, HttpTestingControl
|
||||
`Expected one matching request for criteria "${description}", found ${matches.length} requests.`);
|
||||
}
|
||||
if (matches.length === 0) {
|
||||
throw new Error(`Expected one matching request for criteria "${description}", found none.`);
|
||||
let message = `Expected one matching request for criteria "${description}", found none.`;
|
||||
if (this.open.length > 0) {
|
||||
// Show the methods and URLs of open requests in the error, for convenience.
|
||||
const requests = this.open
|
||||
.map(testReq => {
|
||||
const url = testReq.request.urlWithParams;
|
||||
const method = testReq.request.method;
|
||||
return `${method} ${url}`;
|
||||
})
|
||||
.join(', ');
|
||||
message += ` Requests received are: ${requests}.`;
|
||||
}
|
||||
throw new Error(message);
|
||||
}
|
||||
return matches[0];
|
||||
}
|
||||
|
Reference in New Issue
Block a user