Skip to content

Instantly share code, notes, and snippets.

@evan-boissonnot
Created February 6, 2019 10:22
Show Gist options
  • Save evan-boissonnot/586369282ed40855a147fa47e05fcd39 to your computer and use it in GitHub Desktop.
Save evan-boissonnot/586369282ed40855a147fa47e05fcd39 to your computer and use it in GitHub Desktop.
Unit test of service with http client, with Spy,
/* 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