test('button executes Onclick ', () => {
const wrapper = mount(<ButtonComponent onClick={jest.fn()} />);
wrapper.find('button').simulate('click');
expect(wrapper.props().onClick).toBeCalled();
});
test('MyComponent', () => {
const myFn = jest.fn();
const props = { myFn, ...otherProps }
const wrapper = mount(
<MyComponent {props}/>
);
wrapper.find('button').simulate('click');
wrapper.update();
expect(wrapper.props().myFn).toBeCalled();
});
state = {
inputEntry: '',
}
submitHandler
заменит const payload = event.target.value
на const payload = this.state.inputEntry
handleInputChange = (e) => {
this.setState({inputEntry: e.target.value})
};
const YourComponent = ({ changeOrder }) => (
<Input
onChange={(event) => changeOrder(prop1, event)
// остальной код
/>
)
const mapStateToProps = () => {
return {
// нужный стейт
}
}
const mapDispatchToProps = (dispatch) => {
return {
changeOrder = (prop1, prop2) => dispatch(changeOrder(prop1, prop2)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(YourComponent);