Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/tests / src / jest / jsdom.ts
Size: Mime:
/**
 * @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)