I'm currently working on testing a basic Angular 8 service that utilizes the GeoLocation Service from Web APIs for Angular, which can be found at this link.
public enableGPS() {
if (!this.locationSubscription)
this.locationSubscription = this.geoLocationService.subscribe(
(position) => {
this._currentLocation = position.coords;
}
);
}
Below is an example of the test:
describe("Toggle Location Service", () => {
it("should enable location service", () => {
const testPosition = {
position: {
coords: {
longitude: 1.0,
latitude: 2.0
}
}};
let geoLocationService: GeolocationService = TestBed.get(GeolocationService);
spyOn(geoLocationService, 'subscribe').and.returnValue(
Observable.of(testPosition));
service.enableGPS();
expect(service.currentLocation).toEqual(testPosition);
});
});
However, I've been encountering an issue where service.currentLocation remains undefined and the subscription callback never triggers.