reduxjs / redux-mock-store

A mock store for testing Redux async action creators and middleware.
MIT License
2.5k stars 149 forks source link

error: mockStore is not a function #112

Closed tendolukwago closed 7 years ago

tendolukwago commented 7 years ago

I have a set up that looks kind of like the following:

import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';

const middlewares = [thunk];    
const mockStore = configureStore(middlewares);

//Fetch Action
describe('Fetch Action', () => {
  it('creates a FETCH_ACTION action', async () => {
     const store = mockStore({});
     //...
  });
});

and keep getting "error: mockStore is not a function" when running my tests. Does anything stand out at you?

newyork-anthonyng commented 7 years ago

Could you create a repository that duplicates this error?

tendolukwago commented 7 years ago

Created a repo you can find here.

For some reason, I'm not getting a "Cannot find module 'redux' in index.js" error when trying to run the test? I'm definitely missing something in this whole set up.

newyork-anthonyng commented 7 years ago

@tendolukwago I'm not seeing redux-mock-store being included in the repository.

I'm not too familiar with React Native, but Stack Overflow might be a better place to answer a setup question like you're having.

tendolukwago commented 7 years ago

@newyork-anthonyng Wow, dumb mistake. I updated the repo, if that helps. But sure, I'll see what SO has to offer.

tendolukwago commented 7 years ago

@newyork-anthonyng Some time away from the test repo I created helped. Tests are now passing. I'll let you know if I manage to get everything working in my real project.

tendolukwago commented 7 years ago

@newyork-anthonyng Found a file called "redux-mock-store.js" in my root mocks folder, containing the following:

import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

const middlewares = [thunk];

const mockStore = configureMockStore(middlewares);

export default mockStore

Looks like I mocked the mock store a few weeks ago. Works like a charm now.