// import { jsdom } from 'jsdom' var jsdom = require('jsdom').jsdom; var geolocate = require('mock-geolocation'); var GoogleLoader = require('google-maps'); //load googlemaps into the global namespace GoogleLoader.load((google) => { global.google = google; }); global.document = jsdom('<!doctype html><html><body></body></html>') global.geolocate = geolocate.use(); global.window = document.defaultView global.navigator = global.window.navigator global.navigator.geolocation = global.geolocate;
import { test } from 'mapbox-gl-js-test'; import window from '../../../../src/util/window'; import { createMap } from '../../../util'; import GeolocateControl from '../../../../src/ui/control/geolocate_control'; // window and navigator globals need to be set for mock-geolocation global.window = {}; global.navigator = {}; const geolocation = require('mock-geolocation'); // eslint-disable-line import/no-commonjs geolocation.use(); // assign the mock geolocation to window global.window.navigator = global.navigator; window.navigator.geolocation = global.window.navigator.geolocation; // convert the coordinates of a LngLat object to a fixed number of digits function lngLatAsFixed(lngLat, digits) { return Object.keys(lngLat).reduce((previous, current) => { previous[current] = lngLat[current].toFixed(digits); return previous; }, {}); } test('GeolocateControl with no options', (t) => { const map = createMap(t); t.plan(0); const geolocate = new GeolocateControl(); map.addControl(geolocate); t.end(); });