how to mock the store.dispatch function when using mockStore? with jest

1.6k Views Asked by At

I have this in my react component

console.log(await store.dispatch(getAndSaveImages()));

and my test is:

import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

    it("should call redux store...", () => {
        const store = mockStore({ auth: { isAuth: true } })
        store.dispatch = jest.fn(() => Promise.resolve("its working"));

        component = mount(<Provider store={store}><User history={mockedHistory}/></Provider>);

    });

The problem is that it doesnt mock the dispatch function.

0

There are 0 best solutions below