我对onClick事件进行了以下测试,该测试通过了,但是当我运行npm test --coverage时,该测试没有涵盖。
使用Jest-酶REACT JS
任何建议或解决方案。尝试保持相同的语法 谢谢
这是测试文件:
beforeEach(() =>
wrapper = mount(<BrowserRouter><AddViewModal {...baseProps} /></BrowserRouter>));
it("should call blankRequestClick functions on button click", () => {
baseProps.resetShapeDefinition.mockClear();
baseProps.setRequestId.mockClear();
wrapper.setProps({});
wrapper.find('AddViewModal').setState({
ViewName: 'test',
RequestID: 'test',
Requests: [ {Name:'test'}, ],
});
wrapper.find('#add-new-catalog').at(1).simulate("click");
wrapper.find('.continue_button_div').at(1).simulate("click");
wrapper.find('.continue_button_div').at(2).simulate("click");
expect(baseProps.resetShapeDefinition).toHaveBeenCalled();
expect(baseProps.setRequestId).toHaveBeenCalled();
这是代码:
{ this.state.ViewName !== '' && this.state.allowNext && (this.state.RequestID == '' || this.state.Requests.length == 0)?
<Link id='add-new-catalog' to={{pathname: `${this.props.location.pathname.replace('home', 'Edit')}/1`}} style={{ textDecoration: 'none' }}>
<div onClick={()=>{this.blankRequestClick()}}
className="continue_button_div">
<button className='continue_button' id='continue-blank-add-new-view' title='Continue with Blank Request' type='button'>
Continue with Blank Request
</button>
</div>
</Link> :
目标是使测试通过并单击事件被调用。