Tho*_*ohn 11 mocha.js chai reactjs enzyme
这是一个取消按钮
<div className="cancelFileBtn" onClick={this.props.cancelFileSending}>
Run Code Online (Sandbox Code Playgroud)
我需要模拟它的点击,我尝试了以下测试
wrapper.find('.cancelFileBtn').simulate('click');
Run Code Online (Sandbox Code Playgroud)
但点击功能仍未定义......我是否还错过了其他任何内容?如果有人在模拟中存在任何变化,那将会非常有帮助
<SendMessageButton onClick={this.props.handleClickSendMessage} loadingFile={this.props.loadingFile}/>
Run Code Online (Sandbox Code Playgroud)
在看不到更多代码的情况下不能说太多,希望这会有所帮助:
const wrapper = mount(<Component />);
const cancelBtn = wrapper.find('.cancelFileBtn');
// Test that the button is truthy
expect(cancelBtn).to.have.length(1);
// Simulation
cancelBtn.simulate('click');
// or
cancelBtn.props().onClick();
// Test the output
expect(...).to.equal(...);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5893 次 |
| 最近记录: |