Created
February 6, 2019 10:22
-
-
Save evan-boissonnot/586369282ed40855a147fa47e05fcd39 to your computer and use it in GitHub Desktop.
Unit test of service with http client, with Spy,
This file contains 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
/* tslint:disable:no-unused-variable */ | |
let httpClientSpy: { get: jasmine.Spy }; | |
import { TestBed, async, inject } from '@angular/core/testing'; | |
import { TrainerCalendarService } from './trainer-calendar.service'; | |
import { asyncData } from '../helpers/async-observable-helpers'; | |
import { Appointment } from '../models/appointment'; | |
let service: TrainerCalendarService; | |
describe('Service: TrainerCalendar', () => { | |
beforeEach(() => { | |
httpClientSpy = jasmine.createSpyObj('HttpClient', ['get', 'post']); | |
service = new TrainerCalendarService(<any> httpClientSpy); | |
}); | |
it('should returns list of appointment', () => { | |
const list: Appointment[] = [ | |
new Appointment(), | |
new Appointment() | |
]; | |
httpClientSpy.get.and.returnValue(asyncData<Appointment[]>(list)); | |
service.getAll().then(items => expect(items).toEqual(list, 'same items')); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment