Creating a Mock Store

Learn to create a mock store for testing.

Unlike with simple action creators, our code now relies on dispatch(), which forces us to create a mock instance of a store. To do so, we will use the redux-mock-store library:

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

const mockStore = configureStore([ thunk ]);

Here we create a mock store object with a single thunk middleware. This store object can be used as a regular Redux store. It supports the dispatching of actions and will later allow us to assert our store was sent the correct set of actions.

Get hands-on with 1400+ tech skills courses.