SUT просто:
@Injectable()
export class GetLocationService {
getPosition(): Observable<Object> {
return Observable.create(observer => {
navigator.geolocation.getCurrentPosition((pos: Position) => {
observer.next(pos);
observer.complete();
}),
() => {
alert('Position is not available');
},
{
enableHighAccuracy: true
};
});
}
}
и мой тест для него следующий:
export const POSITION_INFO_FAKE_JSON = {
coords: {
latitude: 32,
longitude: 27
}
};
describe('Get location service', () => {
beforeEachProviders(() => [
GetLocationService
]);
it('should get current position', inject([GetLocationService], (getLocationService) => {
navigator.geolocation = <any>{ getCurrentPosition: function() {
return Observable.create(observer => {
observer.next({ json : function() { return POSITION_INFO_FAKE_JSON; }});
observer.complete();
});
} };
getLocationService.getPosition().subscribe(
(pos: Position) => {
expect(pos.coords.latitude).toBe(434);
expect(pos.coords.longitude).toBe(23);
});
}));
});
Я понятия не имею, почему этот тест всегда проходит, поскольку он определенно должен провалиться. Почему же тогда? Кто-нибудь может указать, что я делаю неправильно здесь?
expect
не выполняются до завершения теста. Прочитайте это: jasmine.github.io/2.0/ - person Sergiu Paraschiv   schedule 19.05.2016