From a622a281d3ca7a4d92ad2f621e8eb3fda794660d Mon Sep 17 00:00:00 2001 From: cexbrayat Date: Thu, 8 Nov 2018 16:34:37 +0100 Subject: [PATCH] test(common): unit tests for http/testing expectOne (#27005) PR Close #27005 --- .../common/http/testing/test/request_spec.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) 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.'); + } + }); });