|
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'); |
|
}); |
|
}); |
|
}); |
This comment has been minimized.
perjerz3434 commentedOct 15, 2018
I need to use async function in order to let tests pass.