Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JSDom Helper
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'])
}
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
You can’t perform that action at this time.