17.10.2018 Views

Angular

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

new Response(<br />

new ResponseOptions({<br />

body: {<br />

accessToken: 'abcdef',<br />

},<br />

}),<br />

),<br />

);<br />

});<br />

const result = await authService.signIn({ password: 'ok', user: 'bruno' });<br />

expect(result).toEqual({<br />

accessToken: 'abcdef',<br />

});<br />

}))<br />

);<br />

// Alternative 2<br />

it('should login user if right credentials are passed', async () => {<br />

const backend: MockBackend = TestBed.get(ConnectionBackend);<br />

const http: Http = TestBed.get(Http);<br />

backend.connections.subscribe((c: MockConnection) => {<br />

c.mockRespond(<br />

new Response(<br />

new ResponseOptions({<br />

body: {<br />

accessToken: 'abcdef',<br />

},<br />

}),<br />

),<br />

);<br />

});<br />

const authService: AuthService = TestBed.get(AuthService);<br />

const result = await authService.signIn({ password: 'ok', user: 'bruno' });<br />

expect(result).toEqual({<br />

accessToken: 'abcdef',<br />

});<br />

});<br />

// Alternative 3<br />

it('should login user if right credentials are passed', async (done) => {<br />

const authService: AuthService = TestBed.get(AuthService);<br />

const backend: MockBackend = TestBed.get(ConnectionBackend);<br />

const http: Http = TestBed.get(Http);<br />

backend.connections.subscribe((c: MockConnection) => {<br />

c.mockRespond(<br />

new Response(<br />

new ResponseOptions({<br />

body: {<br />

accessToken: 'abcdef',<br />

},<br />

}),<br />

),<br />

);<br />

});<br />

GoalKicker.com – <strong>Angular</strong> 2 Notes for Professionals 101

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!