Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NicholasEli/9c358e0fa13d569aea79fe5aee9e4480 to your computer and use it in GitHub Desktop.
Save NicholasEli/9c358e0fa13d569aea79fe5aee9e4480 to your computer and use it in GitHub Desktop.
const position = {
latitude: 45.417224,
longitude: -122.659946
}
const { JSDOM } = require('jsdom')
const jsdom = new JSDOM('<!doctype html><html><body></body></html>')
const { window } = jsdom
global.window = window
global.document = window.document
global.navigator = {
userAgent: 'node.js',
geolocation: {
getCurrentPosition: () => {
return position
}
}
}
const props = Object.getOwnPropertyNames(window)
.filter(prop => typeof global[prop] === 'undefined')
.reduce((result, prop) => ({
...result,
[prop]: Object.getOwnPropertyDescriptor(window, prop),
}), {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment