Repository URL to install this package:
|
Version:
4.0.0 ▾
|
/**
* @see https://airbnb.io/enzyme/docs/guides/jsdom.html
*/
import { JSDOM } from 'jsdom'
const jsdom = new JSDOM(
'<!doctype html><html><head id="head"></head><body id="body"><div id="root"></div></body></html>'
)
const { window } = jsdom
function copyProps(src: any, target: any) {
const props = Object.getOwnPropertyNames(src)
.filter(prop => typeof target[prop] === 'undefined')
.reduce(
(result, prop) => ({
...result,
[prop]: Object.getOwnPropertyDescriptor(src, prop),
}),
{}
)
Object.defineProperties(target, props)
}
const ROOT = global as any
ROOT.window = window as any
ROOT.document = (window as any).document
ROOT.navigator = {
userAgent: 'node.js',
}
copyProps(window, ROOT)
// if (!ROOT.window.Date) {
// ROOT.window.Date = Date
// }
// ROOT.window.Date = global.Date
// somethings check window first...
// Object.assign(ROOT.window, ROOT)