Why Is My Jasmine Spy Not Called?
I am currently writing a unit test for Geolocation API. My Angular component looks as follow: export class HeaderComponent { public lat: number = 56.713; public lng: number = 2
Solution 1:
This happens because spying went wrong.
locationSuccess
and locationError
spies are local variables. They are never used. The fact that params in callFake
have same names doesn't affect anything.
The proper way to do this is to stub navigator.geolocation.getCurrentPosition
:
spyOn(navigator.geolocation, 'getCurrentPosition');
comp.enableNavigatorLocation();
expect(navigator.geolocation.getCurrentPosition).toHaveBeenCalledWith(
comp.locationSuccess,
comp.locationError
);
Post a Comment for "Why Is My Jasmine Spy Not Called?"