diff --git a/packages/common/http/testing/src/backend.ts b/packages/common/http/testing/src/backend.ts index d5311fd551..75a32389b8 100644 --- a/packages/common/http/testing/src/backend.ts +++ b/packages/common/http/testing/src/backend.ts @@ -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]; } diff --git a/packages/common/http/testing/test/request_spec.ts b/packages/common/http/testing/test/request_spec.ts index aefb5d0a4e..2b03893447 100644 --- a/packages/common/http/testing/test/request_spec.ts +++ b/packages/common/http/testing/test/request_spec.ts @@ -36,7 +36,9 @@ describe('HttpClient TestRequest', () => { fail(); } catch (error) { expect(error.message) - .toBe('Expected one matching request for criteria "Match URL: /some-url", found none.'); + .toBe( + 'Expected one matching request for criteria "Match URL: /some-url", found none.' + + ' Requests received are: GET /some-other-url.'); } }); @@ -55,7 +57,8 @@ describe('HttpClient TestRequest', () => { } catch (error) { expect(error.message) .toBe( - 'Expected one matching request for criteria "Match URL: /some-url?query=world", found none.'); + 'Expected one matching request for criteria "Match URL: /some-url?query=world", found none.' + + ' Requests received are: GET /some-url?query=hello.'); } }); });