如何用酶测试嵌套组件的prop?

时间:2019-01-19 18:33:41

标签: javascript reactjs enzyme

我正在尝试测试一个React组件的道具,该组件作为另一个组件的道具。整个内容看起来像这样:

export default ({ propToTest }) => (
  <MainComponent>
    <SubComponent prop1={<SubSubComponent propToTest={propToTest} />} />
  </MainComponent>
);

我想用酶测试组件propToTest的道具SubSubComponent。为此,我编写了以下脚本:

describe('MainComponent test', () => {
  it('takes propToTest correctly', () => {
    const wrapper = shallow(<MainComponent />);
    const subsubComponent = wrapper
      .find('SubComponent')
      .dive()
      .find('SubSubComponent');

    expect(subsubComponent.props().propToTest).toBe(false);
  });
});

但是我遇到了以下错误:

Method “props” is meant to be run on 1 node. 0 found instead.

有什么想法会破坏测试吗?

0 个答案:

没有答案