refactor(enzyme): add url to jsdom constructor for unit test setup (#6356)

This commit is contained in:
Tim Lai
2020-09-01 15:25:04 -07:00
committed by GitHub
parent 1a27c0a8bd
commit b927db86e3

View File

@@ -1,4 +1,8 @@
import win from "../../src/core/window"
// import { configure } from "enzyme" // enzyme@3
// import Adapter from "enzyme-adapter-react-15" // enzyme@3
import { JSDOM } from "jsdom"
function copyProps(src, target) {
const props = Object.getOwnPropertyNames(src)
@@ -10,10 +14,21 @@ function copyProps(src, target) {
Object.defineProperties(target, props)
}
global.window = window
global.document = window.document
global.navigator = {
userAgent: "node.js",
function setUpDomEnvironment() {
const jsdom = new JSDOM("<!doctype html><html><body></body></html>", {
url: "http://localhost/",
})
const { window } = jsdom
global.window = window
global.document = window.document
global.navigator = {
userAgent: "node.js",
}
copyProps(win, window) // use UI's built-in window wrapper
copyProps(window, global)
}
copyProps(win, window) // use UI's built-in window wrapper
copyProps(window, global)
setUpDomEnvironment()
// configure({ adapter: new Adapter() }) // enzyme@3