Updating React component state in Jasmine Test. I don’t know if the previous answer is still true. With React 0.11.1, this code works fine:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | var React = require('react/addons'); var TestUtils = React.addons.TestUtils; jest.dontMock('public/components/MyThing.jsx'); var MyThing = require('public/components/MyThing.jsx'); describe('MyThing', function() { var html; describe('#render', function() { beforeEach(function(){ var component = MyThing(); var componentInstance = TestUtils.renderIntoDocument(component); componentInstance.setState({isCool: true}); html = componentInstance.getDOMNode().textContent; }); it('includes something cool', function(){ expect(html).toContain('something cool'); }); }); }); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.