What is the correct way of unit testing a React component prop update.
Here is my test fixture;
describe(\'updating the value\', function(){
If you re-render the element with different props in the same container node, it will be updated instead of re-mounted. See React.render.
In your case, you should use ReactDOM.render
directly instead of TestUtils.renderIntoDocument
. The later creates a new container node every time it is called, and thus a new component too.
var node, component;
beforeEach(function(){
node = document.createElement('div');
component = ReactDOM.render( , node);
});
it('should update the state of the component when the value prop is changed', function(){
// `component` will be updated instead of remounted
ReactDOM.render( , node);
// Assert that `component` has updated its state in response to a prop change
expect(component.state.value).toBe(false);
});