redux-mock-store is a utility package designed to facilitate testing of Redux asynchronous action creators and middleware by providing a mocked Redux store. Its primary function is to capture a log of all dispatched actions, which can then be asserted against in tests. Unlike a real Redux store, `redux-mock-store` does not process actions through reducers, meaning its internal state never updates. This library is currently at version 1.5.5. However, since this version, `redux-mock-store` has been officially deprecated by the Redux team. The recommended testing practice now involves using a real Redux store to test the combined behavior of action creators, reducers, and selectors, asserting on observable state changes rather than just dispatched actions. This package is therefore in a deprecated status, with an implied end of active development and maintenance.
npm install redux-mock-storeVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to test asynchronous Redux actions and middleware (like `redux-thunk`) by initializing a mock store and asserting on the captured dispatched actions.
Migrate your tests away from `redux-mock-store`. Refactor tests to utilize a real Redux store and assert against the actual state changes and selector outputs, following the latest official Redux testing documentation.
When using `redux-mock-store`, limit your assertions to the array of dispatched actions obtained via `store.getActions()`. If you need to test state changes, you must use a real Redux store instead.
Adopt the Redux team's recommended testing strategy, which involves setting up a functional Redux store for tests. This allows for comprehensive testing of action creators, reducers, and selectors in an integrated manner, asserting on the final observable state.
Ensure that `store.dispatch()` for asynchronous actions is `await`ed or returns a Promise, and `store.getActions()` is called *after* the promise resolves. Verify all necessary middlewares (e.g., `redux-thunk`) are correctly configured with `configureStore`.
For ESM, use `import configureStore from 'redux-mock-store'`. For CommonJS, use `const configureStore = require('redux-mock-store').default`.