How to mock bindActionCreators using jest enzyme

Viewed 609

in js file

import { bindActionCreators } from "redux";

const mapDispatchToProps = dispatch => {
  const MyActions = bindActionCreators(MyActions, dispatch);

  return {
    actions: {
      method1: () => {
        MyActions.myActionMethod();
      },
}

Now I want to test if calling of method1 dispatches MyActions.myActionMethod

my .test.js code

 it("Should call myAction", () => {
    jest
      .spyOn(MyActions, "myActionMethod")
      .mockImplementation(() => {
        console.log("calling mock imple");

      });

    enzymeWrapper.props().actions.method1();
  });

can anyone suggest to me how to mock bindActionCreators ?

1 Answers

I got the solution for it, we need to spy or mock actions before enzymeWrapper creation which means before calling shallow method.

Related