我正在为PopUp组件编写一个小型测试。但是,我收到此错误:方法“文本”应在1个节点上运行。找到0个。我正在学习过程中,任何帮助将不胜感激。谢谢 这是我的component.tests.js
const small = popUp.find('small');
expect(small).toHaveLength(1);
expect(small.text()).toBe(messages['en'] .
['segments.create.timeline.isScheduled']);
expect(warning).toBeDefined();
expect(popover).toBeDefined();
expect(message).toBeDefined();
});
});
这是我的component.js
class SegmentWarningPopup extends React.Component {
state = {
anchorEl: null,
};
handleClick = event => {
this.setState({
anchorEl: event.currentTarget,
});
};
handleClose = () => {
this.setState({
anchorEl: null,
});
};
render() {
const { anchorEl } = this.state;
const open = Boolean(anchorEl);
return (
<div>
<Warning size="small" className="duration-has-changed-icon" onClick={this.handleClick}/>
<Popover
id="durationHasChanged"
open={open}
anchorEl={anchorEl}
onClose={this.handleClose}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
transformOrigin={{
vertical: 'top',
horizontal: 'left',
}}
PaperProps={{
className: 'warning-popover-paper'
}}
>
<FormattedMessage id={"segments.create.timeline.isScheduled"} description="text"/>
</Popover>
</div>
);
}
}
SegmentWarningPopup.propTypes = {
targetEventObj: PropTypes.object
};
export default SegmentWarningPopup;
答案 0 :(得分:1)
您只需要.find
<Warning>
组件本身即可:
popUp.find(Warning)