I have a form and the corresponding event handlers as below
handleSubmit(event){
event.preventDefault();
this.submitBooking();
}
submitBooking(){
console.log("form submited");
}
render(){
return(
<form className="form" onSubmit={this.handleSubmit}>
// form code goes here
</form>
)
}
I have written the following test case to check if handleSubmit() gets called on form submission but it does not work.
describe("Testing function call", () => {
test("Testing handleSubmit called", () => {
const wrapper = shallow(<Book />);
wrapper.find("form").simulate("submit");
const instance = wrapper.instance();
instance.handleSubmit = jest.fn();
expect(instance.handleSubmit).toBeCalled();
});
})