I'm using GeolocationPositionError which should be built in, but es-lint is telling me it's not defined. Webstorm isn't helping me import it. Where do I import this from, or is there another issue here?
The code works:
} catch (error) {
console.log(error);
if (error instanceof GeolocationPositionError) {
console.log("Location access was denied");
return;
} else {
setTimeout(() => {
console.log("retrying");
dispatch(fetchUserLocation());
}, 2000);
}
}
I mocked it like this:
class GeolocationPositionError extends Error {
readonly code: number;
readonly message: string;
readonly PERMISSION_DENIED: number;
readonly POSITION_UNAVAILABLE: number;
readonly TIMEOUT: number;
constructor(msg?: string) {
super(msg);
}
}
global.GeolocationPositionError = GeolocationPositionError;
It's not a true "mock", but it allows jsdom to properly resolve the global. You can spy on it using jest.spyOn(global, "GeolocationPositionError")
Try this:
if (error instanceof window.GeolocationPositionError)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With