Skip to content

Instantly share code, notes, and snippets.

@DrewML
Created September 6, 2016 16:07
Show Gist options
  • Save DrewML/9b0d447edc1c5e03c2d8c45cc3ebe90c to your computer and use it in GitHub Desktop.
Save DrewML/9b0d447edc1c5e03c2d8c45cc3ebe90c to your computer and use it in GitHub Desktop.
const jsdom = require("jsdom").jsdom;
const doc = jsdom(undefined, { url: "http://localhost" });
const jsdomWindow = doc.defaultView;
global.document = doc;
global.window = new Proxy(jsdomWindow, {
set(target, property, value) {
global[property] = value;
return value;
}
});
Object.keys(window).forEach(key => {
if (!global[key]) {
global[key] = window[key];
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment