单元测试 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);
});
});
这工作正常并且测试通过,但是这会显示一条react警告消息
'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.'
我只想测试一个属性的更新,而不是创建具有不同属性的元素的新实例。有没有更好的方法来进行此属性更新?