Skip to content

Instantly share code, notes, and snippets.

@AntonGorelov
Created May 4, 2020 10:28
Show Gist options
  • Save AntonGorelov/e503a8d747fca93a2236b950837756da to your computer and use it in GitHub Desktop.
Save AntonGorelov/e503a8d747fca93a2236b950837756da to your computer and use it in GitHub Desktop.
describe('VideoService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpModule],
providers: [
{ provide: VIMEO_API_URL, useValue: 'http://example.com' },
VideoService,
{ provide: XHRBackend, useClass: MockBackend },
]
});
});
describe('getVideos()', () => {
it('should return an Observable<Array<Video>>',
inject([VideoService, XHRBackend], (videoService, mockBackend) => {
const mockResponse = {
data: [
{ id: 0, name: 'Video 0' },
{ id: 1, name: 'Video 1' },
{ id: 2, name: 'Video 2' },
{ id: 3, name: 'Video 3' },
]
};
mockBackend.connections.subscribe((connection) => {
connection.mockRespond(new Response(new ResponseOptions({
body: JSON.stringify(mockResponse)
})));
});
videoService.getVideos().subscribe((videos) => {
expect(videos.length).toBe(4);
expect(videos[0].name).toEqual('Video 0');
expect(videos[1].name).toEqual('Video 1');
expect(videos[2].name).toEqual('Video 2');
expect(videos[3].name).toEqual('Video 3');
});
}));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment