test(common): unit test for http/testing expectOne with several requests (#27005)

PR Close #27005
This commit is contained in:
cexbrayat 2020-01-22 08:32:56 +01:00 committed by Misko Hevery
parent 115b7e42c6
commit c77cf717aa
1 changed files with 20 additions and 0 deletions

View File

@ -61,4 +61,24 @@ describe('HttpClient TestRequest', () => {
' Requests received are: GET /some-url?query=hello.'); ' 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.');
}
});
}); });