我是开玩笑的新手。我的组件看起来像这样。
class ComponentToTest extends React.Component {
searchName = () => {
return axios.get(...)
}
render() {
return(
<Form onSubmit={handleSubmit(save)}>
<SomeChildComponent searchName={ (searchTerm: string) => this.searchName(searchTerm)} />
</Form>
)
}
}
`ComponentToTest.test.js`
it('should call `handleSubmit` with `save`', () => {
const store = createStore((state) => state, { app: {} });
const onSave = jest.fn().mockReturnValue(() => {});
const props: any = { handleSubmit: onSave };
const tree = mount(
<Provider store={store}>
<ComponentToTest {...props} />
</Provider>,
);
tree.find('button').simulate('submit');
expect(onSave).toHaveBeenCalled();
});
运行此测试后出现错误。有什么方法可以模拟对searchName的调用并返回promise?