在js文件中
import { bindActionCreators } from "redux";
const mapDispatchToProps = dispatch => {
const MyActions = bindActionCreators(MyActions, dispatch);
return {
actions: {
method1: () => {
MyActions.myActionMethod();
},
}
现在我想测试一下,调用method1是否会派发MyActions.myActionMethod。
我的.test.js代码
it("Should call myAction", () => {
jest
.spyOn(MyActions, "myActionMethod")
.mockImplementation(() => {
console.log("calling mock imple");
});
enzymeWrapper.props().actions.method1();
});
谁能告诉我如何模拟bindActionCreators?
我找到了解决方法,我们需要监视或模拟动作之前 enzymeWrapper
创作,也就是说,在调用 shallow
方法。