The SUT is just:
@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
};
});
}
}
and my test for it is the following:
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);
});
}));
});
I have no idea why this test is always passing, since it definitaly should fail. Why so then? Anyone could point what I am doing wrong here ?