我有一个表单和相应的事件处理程序,如下所示
handleSubmit(event){
event.preventDefault();
this.submitBooking();
}
submitBooking(){
console.log("form submited");
}
render(){
return(
<form className="form" onSubmit={this.handleSubmit}>
// form code goes here
</form>
)
}
我已经编写了以下测试用例,以检查是否在表单提交时调用handleSubmit(),但是它不起作用。
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();
});
})