Created
May 18, 2017 18:19
-
-
Save dherges/5cedf14b33d4d8264a6fad6073f9ec41 to your computer and use it in GitHub Desktop.
Angular Testing Snippets: Services over HTTP (4)
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(`FeatureService`, () => { | |
| /** ... set up ... **/ | |
| it(`should emit 'true' for 200 Ok`, | |
| async(inject([ FeatureService, MockBackend ], | |
| (service: FeatureService, mockBackend: MockBackend) => { | |
| // 1. prepare fake response from `MockBackend` | |
| mockBackend.connections.subscribe((c: MockConnection) => { | |
| // 3. respond to `FeatureService` with a 200 Ok | |
| c.mockRespond(new Response(new ResponseOptions({ | |
| body: '', | |
| status: 200 | |
| }))); | |
| }); | |
| // 2. dispatch the http request | |
| service.login('foo', 'bar') | |
| .subscribe((status: boolean) => { | |
| // 4. ensure that `FeatureService` reports login success | |
| expect(status).toBeTruthy(); | |
| }); | |
| }))); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment