Created
July 25, 2017 17:02
-
-
Save izifortune/3ac7786a7033cc39eb588d0888ff96c9 to your computer and use it in GitHub Desktop.
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
import { Observable } from 'rxjs'; | |
import { SampleService } from './sample.service'; | |
const mockAirports = { | |
DUB: { name: 'Dublin' }, | |
WRO: { name: 'Wroclaw' }, | |
MAD: { name: 'Madrid' } | |
}; | |
describe('Service: SampleService no TestBed', () => { | |
let service: SampleService; | |
let http = { | |
get: jest.fn(() => | |
Observable.of(mockAirports) | |
) | |
}; | |
beforeEach(() => { | |
service = new SampleService(http as any); | |
}); | |
it('fetchAll$: should return a sorted list', () => { | |
service.fetchAll$().subscribe((airports) => { | |
expect(http.get).toBeCalledWith('https://foo.bar.com/airports'); | |
expect(airports.length).toBe(3); | |
expect(airports[2][0]).toBe('WRO'); | |
}); | |
}); | |
it('fetchByIATA$: should return the selected airport', () => { | |
service.fetchByIATA$('MAD').subscribe((airport) => { | |
expect(http.get).toBeCalledWith('https://foo.bar.com/airports'); | |
expect(airport.name).toBe('Madrid'); | |
}); | |
}); | |
}); |
describe('CompanyService', () => {
it('should destruct companies key into company list', async(() => {
const companies = [mockCompany()];
const httpMock = { get: jest.fn(() => of({companies})) };
const service = new CompanyService(httpMock as any);
service.getCompanies().subscribe(data => {
expect(httpMock.get).toHaveBeenCalledWith('/assets/data/companies.json');
expect(data).toBe(companies);
});
}));
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I need to use async function in order to let tests pass.