我正在使用带有反应的索环来呈现我的应用程序的 UI。当用户单击按钮时,我会显示一个图层组件。一切正常,但我不知道如何测试图层的孩子。我正在使用酶、摩卡和柴作为测试套件。这是我的组件代码的代码:
<Layer align="right" closer>
<Header size="large" justify="between" align="center">
<Button icon={<CloseIcon />} plain={true} onClick={ props.hide }/>
</Header>
<Section key={index} pad={{ horizontal: 'large', vertical: 'small' }}>
{ props.list }
</Section>
</Layer>
这是我的测试:
const wrapper = shallow(<MyComponent />);
const layer = wrapper.find(Layer);
//this works
expect(layer).to.have.length.of(1);
const section = layer.find(Section);
//and this fails
expect(section).to.have.length.of(1);
查看应用程序中渲染的组件,我发现 grommet 以这种方式渲染他的 Layer 组件:
<Layer><span style={{ display: 'none'}}></span></Layer>
任何人都可以帮助我吗?谢谢