Skip to content

Instantly share code, notes, and snippets.

@evangoer
Created July 23, 2014 07:17
Show Gist options
  • Save evangoer/d34f990d7a1c04f910ef to your computer and use it in GitHub Desktop.
Save evangoer/d34f990d7a1c04f910ef to your computer and use it in GitHub Desktop.
jsdom + mocha testing of a React component, with no build step required.
var React = require('React/addons'),
assert = require('assert');
var Hello = React.createClass({
render: function () {
return React.DOM.p(null, 'hello');
}
});
var jsdom = require('jsdom');
describe('A', function () {
beforeEach(function () {
global.document = jsdom.jsdom();
global.window = document.parentWindow;
});
it('B', function () {
React.renderComponent(Hello(), document.body);
assert.equal(document.querySelector('p').innerHTML, 'hello');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment