Created
April 12, 2018 10:16
-
-
Save iampeterbanjo/c2ebbed02933552cacbffc8b3f32027c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// setup test environment for jest and jsdom to | |
// allow code like window.location.href = '/' | |
// # setupEnvironment.js | |
const JSDOMEnvironment = require('jest-environment-jsdom'); | |
module.exports = class JSDOMEnvironmentGlobal extends JSDOMEnvironment { | |
constructor(config) { | |
super(config); | |
this.global.jsdom = this.dom; | |
this.originalEnv = Object.assign({}, process.env); | |
process.env.VARIABLE = 'something'; | |
} | |
teardown() { | |
this.global.jsdom = null; | |
process.env = this.originalEnv; | |
return super.teardown(); | |
} | |
}; | |
// #package.json | |
"jest": { | |
... | |
"testEnvironment": "<rootDir>/test/setupEnvironment.js" | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment