Created
March 3, 2017 18:06
-
-
Save marcysutton/6ce143416f993d194750ad051b4d7383 to your computer and use it in GitHub Desktop.
JSDom Helper
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
module.exports = function (grunt) { | |
'use strict' | |
require('load-grunt-tasks')(grunt) | |
grunt.initConfig({ | |
mochaTest: { | |
test: { | |
options: { | |
reporter: 'spec', | |
require: ['babel-register', 'src/jsdom-setup.js'] | |
}, | |
src: ['src/**/*.test.js'] | |
} | |
} | |
}) | |
grunt.registerTask('test', ['mochaTest']) | |
} |
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
import { jsdom } from 'jsdom' | |
import 'jsdom-global/register' | |
export function jsdomSetup () { | |
if (global.document && global.window) { | |
global.document = jsdom('<!doctype html><html><body></body></html>') | |
global.window = global.document.defaultView | |
return | |
} | |
// Make all window properties available on the mocha global | |
Object.keys(global.window) | |
.filter(key => !(key in global)) | |
.forEach(key => { | |
global[key] = global.window[key] | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment