我是单元测试的新手,想知道如何为以下onClick设置测试
我之前已经做过一些onClicks,但是如何调用以下事件并使它通过我的测试:
使用JEST和酶-React js-
file.js
return (
<DropdownItem key={action.RouteId}
id={action.RouteName}
onClick={() => {
if(this.props.action && (this.props.action.routeId !== action.RouteId)){
this.props.setTarget(null);
this.props.setAction(action);
}
}}>
通常,这就是我设置onClick测试的方式:如何基于此来使上面的测试起作用:
test.file.js
beforeEach(() => wrapper = mount(<BrowserRouter><Component {...baseProps} /></BrowserRouter>));
it(" should call button click event", () => {
baseProps.onClick.mockClear();
wrapper.setProps({});
wrapper.find('COMPONENT').setState({
});
wrapper.update()
wrapper.find('#id').simulate("click");
expect(toJson(wrapper)).toMatchSnapshot();
});