From c77cf717aa0723c939df07972befe74cac285a30 Mon Sep 17 00:00:00 2001 From: cexbrayat Date: Wed, 22 Jan 2020 08:32:56 +0100 Subject: [PATCH] test(common): unit test for http/testing expectOne with several requests (#27005) PR Close #27005 --- .../common/http/testing/test/request_spec.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/common/http/testing/test/request_spec.ts b/packages/common/http/testing/test/request_spec.ts index 2b03893447..92d78399d2 100644 --- a/packages/common/http/testing/test/request_spec.ts +++ b/packages/common/http/testing/test/request_spec.ts @@ -61,4 +61,24 @@ describe('HttpClient TestRequest', () => { ' Requests received are: GET /some-url?query=hello.'); } }); + + it('throws if no request matches with several requests received', () => { + const mock = new HttpClientTestingBackend(); + const client = new HttpClient(mock); + + let resp: any; + client.get('/some-other-url?query=world').subscribe(body => { resp = body; }); + client.post('/and-another-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.' + + ' Requests received are: GET /some-other-url?query=world, POST /and-another-url.'); + } + }); });