Last active
December 20, 2017 22:28
-
-
Save silvenon/0567b71204de85b411c3 to your computer and use it in GitHub Desktop.
Mocha setup I use for testing React with jsdom.
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 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