反应还很新,我正在使用反应来进行表单验证。 我尝试测试下面定义的createTask():
renderForm(handleSubmit) {
return (
<form
onSubmit={handleSubmit}
>
<div className="task-details">
{(this.createTask()}
</div>
</form>);
}
render() {
return (
<Form
onSubmit={this.handleApplyClick}
render={this.renderForm}
validate={this.validateForm}
/>
);
}
如何模拟renderForm,以便可以测试是否已调用createTask? jest.fn()对我不起作用,如下所示
beforeEach(() => {
testPanel = mountWithIntl(<TestPanel/>);
});
it('calls the createHeader', () => {
testPanel.find('panelName').instance().renderForm = jest.fn();
testPanel.find('panelName').instance().render();
testPanel.update();
expect(testPanel.find('panelName').instance().createHeader)
.toHaveBeenCalled();
});
预先感谢