单元测试React组件prop更新的正确方法是什么.
这是我的测试夹具;
describe('updating the value', function(){
var component;
beforeEach(function(){
component = TestUtils.renderIntoDocument(<MyComponent value={true} />);
});
it('should update the state of the component when the value prop is changed', function(){
// Act
component.props.value = false;
component.forceUpdate();
// Assert
expect(component.state.value).toBe(false);
});
});
Run Code Online (Sandbox Code Playgroud)
这工作正常并且测试通过,但是这会显示反应警告消息
'Warning: Dont set .props.value of the React component <exports />. Instead specify the correct value when initially creating the element or use React.cloneElement to make a new element with updated props.'
Run Code Online (Sandbox Code Playgroud)
我想要测试的是属性的更新,而不是创建具有不同属性的元素的新实例.有没有更好的方法来进行此属性更新?