Skip to content

Instantly share code, notes, and snippets.

@i-like-robots
Created April 29, 2014 13:39
Show Gist options
  • Save i-like-robots/11400700 to your computer and use it in GitHub Desktop.
Save i-like-robots/11400700 to your computer and use it in GitHub Desktop.
React unit test component with Jasmine
/** @jsx React.DOM */
var MyComponent = React.createClass({
render: function () {
return (
<p ref="p">{this.props.children}</p>
);
}
});
/** @jsx React.DOM */
var React = require("../vendor/react/react-with-addons");
var MyComponent = require("../app/component/my-component");
var TestUtils = React.addons.TestUtils;
describe("My Component", function() {
describe("A feature", function() {
afterEach(function() {
if (instance && TestUtils.isCompositeComponent(instance) && instance.isMounted()) {
React.unmountComponentAtNode(instance.getDOMNode().parent);
}
});
beforeEach(function() {
instance = TestUtils.renderIntoDocument(<MyComponent>Some text</MyComponent>);
});
it("Check Text Assignment", function() {
expect(instance.refs.p).toBeDefined();
expect(instance.refs.p.props.children).toBe("Some text");
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment