2gis/mock-geolocation

Module does not work with node.js

Opened this issue · 3 comments

This module does not work with node.js because node doesn't have window or navigator objects.

I made a fork of the repo and modified the module so that it checks for the existence of those objects and, if they don't exist, attaches two objects under node.js global module.

Is there any interest in an PR?

Trufi commented

@tiagofassoni Yes, it will be great

@tiagofassoni Any chance you can submit a PR on your change? I would like to see this supported.

This is the code I used to get it working in node.js

// window and navigator globals need to be set for mock-geolocation
global.window = {};
global.navigator = {};
const geolocation = require('mock-geolocation');
geolocation.use();

// assign the mock geolocation to window
global.window.navigator = global.navigator;
window.navigator.geolocation = global.window.navigator.geolocation;