refactor(enzyme): add url to jsdom constructor for unit test setup (#6356)
This commit is contained in:
@@ -1,4 +1,8 @@
|
|||||||
import win from "../../src/core/window"
|
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) {
|
function copyProps(src, target) {
|
||||||
const props = Object.getOwnPropertyNames(src)
|
const props = Object.getOwnPropertyNames(src)
|
||||||
@@ -10,10 +14,21 @@ function copyProps(src, target) {
|
|||||||
Object.defineProperties(target, props)
|
Object.defineProperties(target, props)
|
||||||
}
|
}
|
||||||
|
|
||||||
global.window = window
|
function setUpDomEnvironment() {
|
||||||
global.document = window.document
|
const jsdom = new JSDOM("<!doctype html><html><body></body></html>", {
|
||||||
global.navigator = {
|
url: "http://localhost/",
|
||||||
userAgent: "node.js",
|
})
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user