Skip to content

Instantly share code, notes, and snippets.

@marcysutton
Created March 3, 2017 18:06
Show Gist options
  • Save marcysutton/6ce143416f993d194750ad051b4d7383 to your computer and use it in GitHub Desktop.
Save marcysutton/6ce143416f993d194750ad051b4d7383 to your computer and use it in GitHub Desktop.
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