test(common): unit tests for http/testing expectOne (#27005)
PR Close #27005
This commit is contained in:
parent
e672b1f2ac
commit
a622a281d3
|
@ -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.');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue