diff --git a/packages/common/http/testing/test/request_spec.ts b/packages/common/http/testing/test/request_spec.ts index ee7ba15c6f..aefb5d0a4e 100644 --- a/packages/common/http/testing/test/request_spec.ts +++ b/packages/common/http/testing/test/request_spec.ts @@ -22,4 +22,40 @@ describe('HttpClient TestRequest', () => { expect(resp).toBeNull(); }); + + it('throws if no request matches', () => { + const mock = new HttpClientTestingBackend(); + const client = new HttpClient(mock); + + let resp: any; + client.get('/some-other-url').subscribe(body => { resp = body; }); + + try { + // expect different URL + mock.expectOne('/some-url').flush(null); + fail(); + } catch (error) { + expect(error.message) + .toBe('Expected one matching request for criteria "Match URL: /some-url", found none.'); + } + }); + + it('throws if no request matches the exact parameters', () => { + const mock = new HttpClientTestingBackend(); + const client = new HttpClient(mock); + + let resp: any; + const params = {query: 'hello'}; + client.get('/some-url', {params}).subscribe(body => { resp = body; }); + + try { + // expect different query parameters + mock.expectOne('/some-url?query=world').flush(null); + fail(); + } catch (error) { + expect(error.message) + .toBe( + 'Expected one matching request for criteria "Match URL: /some-url?query=world", found none.'); + } + }); });