Last active
April 19, 2019 12:12
-
-
Save EvidentlyCube/b30e97864824bcfcce3401a6c4c1e7f4 to your computer and use it in GitHub Desktop.
Hooking JSDom for PixiJS to run correctly in Mocha
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
/** | |
* Adapted from https://github.com/rstacruz/jsdom-global | |
* Make sure this file is registered when running tests by adding this to the command with which you run mocha: | |
* -r <path>/hookJsdom.js | |
*/ | |
const JSDOM = require( 'jsdom' ).JSDOM; | |
const jsdomOptions = { | |
url: 'http://localhost/' | |
}; | |
const jsdomInstance = new JSDOM( '', jsdomOptions ); | |
const { window } = jsdomInstance; | |
Object.getOwnPropertyNames( window ) | |
.filter( property => !property.startsWith( '_' ) ) | |
.forEach( key => global[key] = window[key] ); | |
global.window = window; | |
window.console = global.console; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment