Created
April 29, 2014 13:39
-
-
Save i-like-robots/11400700 to your computer and use it in GitHub Desktop.
React unit test component with Jasmine
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
/** @jsx React.DOM */ | |
var MyComponent = React.createClass({ | |
render: function () { | |
return ( | |
<p ref="p">{this.props.children}</p> | |
); | |
} | |
}); |
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
/** @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