Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mocha setup I use for testing React with jsdom.
import jsdom from 'jsdom';
import assert from 'assert';
describe('suite', () => {
let React, utils, Component;
before(() => {
global.document = jsdom.jsdom('<!DOCTYPE html><html><head></head><body></body></html>');
global.window = document.parentWindow;
global.navigator = {userAgent: 'node.js'};
React = require('react/addons');
utils = React.addons.TestUtils;
Component = require('../components/component');
});
it('should do something', () => {
const el = utils.renderIntoDocument(
<Component />
);
assert(utils.isComponent(el));
});
after(() => {
window.close();
delete document;
});
});
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.