酶引发TypeError中的“模拟”:无法读取未定义的属性“ props”

时间:2019-02-05 06:17:32

标签: javascript reactjs jestjs enzyme

我正在使用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>,

谢谢。

0 个答案:

没有答案