Skip to content

Instantly share code, notes, and snippets.

@dherges
Last active December 13, 2017 15:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dherges/2f70913a952d0d7e936b9aaeb3062651 to your computer and use it in GitHub Desktop.
Save dherges/2f70913a952d0d7e936b9aaeb3062651 to your computer and use it in GitHub Desktop.
Angular HttpClient (3)
describe(`FakeHttpClientResponses`, () => {
it(`should expect a GET /foo/bar`, async(inject([HttpClient, HttpTestingController],
(http: HttpClient, backend: HttpTestingController) => {
http.get('/foo/bar').subscribe();
backend.expectOne({
url: '/foo/bar',
method: 'GET'
});
})));
it(`should not issue a PUT request`, async(inject([HttpClient, HttpTestingController],
(http: HttpClient, backend: HttpTestingController) => {
http.post('/allez', { value: 123 }).subscribe();
http.get('/allez').subscribe();
http.delete('/allez').subscribe();
backend.expectNone((req: HttpRequest<any>) => {
return req.method === 'PUT';
});
})));
it(`should NOT fail when sending an un-matched request`, async(inject([HttpClient, HttpTestingController],
(http: HttpClient, backend: HttpTestingController) => {
http.get('/foo/bar').subscribe();
backend.match('/foo');
})));
it(`should fail when verifying an un-matched request`, async(inject([HttpClient, HttpTestingController],
(http: HttpClient, backend: HttpTestingController) => {
http.get('/foo/bar').subscribe();
backend.match('/foo');
backend.verify();
})));
it(`should fail when not sending an expected request`, async(inject([HttpClient, HttpTestingController],
(http: HttpClient, backend: HttpTestingController) => {
http.get('/foo/bar').subscribe();
backend.expectOne('/foo');
})));
it(`should fail when sending an non-expected request`, async(inject([HttpClient, HttpTestingController],
(http: HttpClient, backend: HttpTestingController) => {
http.get('/foo/bar').subscribe();
backend.expectNone('/foo/bar');
})));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment