Created
July 23, 2014 07:17
-
-
Save evangoer/d34f990d7a1c04f910ef to your computer and use it in GitHub Desktop.
jsdom + mocha testing of a React component, with no build step required.
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
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