Skip to content

Instantly share code, notes, and snippets.

@nikolaymatrosov
Created August 5, 2015 11:38
Show Gist options
  • Save nikolaymatrosov/3c9636a5c46b4022535e to your computer and use it in GitHub Desktop.
Save nikolaymatrosov/3c9636a5c46b4022535e to your computer and use it in GitHub Desktop.
Mocha test setup for testing React using JsDOM
{
...
"scripts": {
"test": "mocha --recursive --require test_setup.js src/**/*.spec.js",
},
"devDependencies": {
"babel": "5.6.14",
"babel-core": "5.6.20",
"babel-plugin-rewire": "0.1.5",
"chai": "3.0.0",
"jsdom": "3.1.2",
"mocha": "2.2.5",
"sinon": "1.15.4"
}
...
}
require('babel/register')({
stage: 0,
plugins: ['rewire']
});
var jsdom = require('jsdom').jsdom('<!doctype html><html><body></body></html>');
global.document = jsdom;
global.window = document.parentWindow;
global.navigator = window.navigator;
global.expect = require('chai').expect;
global.assert = require('chai').assert;
var sinon = require('sinon');
var sinonStubPromise = require('sinon-stub-promise');
sinonStubPromise(sinon);
global.sinon = sinon;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment