fix test support

This commit is contained in:
Devin Howard 2017-09-09 09:29:05 -07:00
parent c0021c7d40
commit 5c01754df1

View file

@ -1,22 +1,22 @@
const jsdom = require('jsdom') const jsdom = require('jsdom')
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>')
const win = doc.defaultView
global.document = doc const { JSDOM } = jsdom
global.window = win const dom = new JSDOM('<!doctype html><html><body></body></html>')
global.document = dom.window.document
global.window = dom.window
// take all properties of the window object and also attach it to the // take all properties of the window object and also attach it to the
// mocha global object // mocha global object
propagateToGlobal(win) propagateToGlobal(dom.window)
// from mocha-jsdom https://github.com/rstacruz/mocha-jsdom/blob/master/index.js#L80 // from mocha-jsdom https://github.com/rstacruz/mocha-jsdom/blob/master/index.js#L80
function propagateToGlobal(window) { function propagateToGlobal(window) {
for (let key in window) { global.HTMLElement = window.HTMLElement
if (!window.hasOwnProperty(key)) continue Object.keys(window).forEach(key => {
if (key in global) continue if (key in global) return
global[key] = window[key] global[key] = window[key]
} })
} }
// Metamaps dependencies fixes // Metamaps dependencies fixes