我正在使用Jest和Enzyme测试我的React Button组件。我需要触发单击按钮。这是测试代码片段:
it('closes cancel modal on click', () => {
wrapper.find(Button).at(4).simulate('click');
});
这会引发错误:
TypeError: Cannot read property 'props' of undefined
从上述代码中删除simulate('click')
可以消除错误。我不确定为什么会这样?有任何线索吗?
这是React组件片段:
<Button
uiType="secondary"
appearance="inversed"
onClick={() => {
this.setState({
showCancelModal: false,
});
}}
>
{i18n('lorem ipsum')}
</Button>,
谢谢。