2
如何在调用updateItem之后让我的测试反映组件的新状态。我确实尝试了rendered.update(),但是我一定不知道如何工作。谢谢。阶级通过酶在类上调用方法时获取组件的更新状态
方法:
updateItem (id) {
return updateItem(id)
.then((result) => {
this.setState({
item: {blah:'blah'}
});
}, (error) => {
throw error;
});
}
测试:
it("should update item accordingly",() => {
const rendered = shallow(React.createElement(Item));
const result = rendered.instance().updateItem();
expect(rendered.state('item')).toEqual({blah:'blah'});
})
我不认为它会这样工作,通常如何在你的组件中调用函数。 –
作为子组件回调 – groovy
好的,但你可以从子元素道具中获取并调用它。 –