我已经使用了Material-ui的List组件。在此组件内部,我有一个prop副标题,其中包含一个复选框。我想测试复选框的onClick功能。
<List
component="nav"
subheader={<span style={{ display: 'inline-flex', width: '100%' }}>
< ListSubheader style={{ top: 'inherit', width: '80%', fontSize: '30px', fontWeight: 'bold' }}>
{HEADING.industries}
</ListSubheader >
<Checkbox
color="default"
checked={this.state.checkedSelectAll}
onClick={handleSelectAll}
/>
<Typography className="selectAllText">
Select All
</Typography>
</span>}
>
我写了:
it('should call handleSelectAll', () => {
wrapper = shallow(<IndustryGroupModal {...props} />);
wrapper.find(Checkbox).simulate('click');
});
出现此错误:
Method “simulate” is meant to be run on 1 node. 0 found instead.
答案 0 :(得分:0)
尝试一下,我认为应该足够了:
it('should call handleSelectAll', () => {
wrapper = shallow(<IndustryGroupModal {...props} />);
wrapper.prop("subheader").props.children[1].props.onClick()
});
我希望这能解决您的问题,祝您愉快!