Last active
December 13, 2017 15:40
-
-
Save dherges/2f70913a952d0d7e936b9aaeb3062651 to your computer and use it in GitHub Desktop.
Angular HttpClient (3)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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