{"id":17467,"library":"redux-mock-store","title":"Redux Mock Store","description":"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.","status":"deprecated","version":"1.5.5","language":"javascript","source_language":"en","source_url":"https://github.com/arnaudbenard/redux-mock-store","tags":["javascript"],"install":[{"cmd":"npm install redux-mock-store","lang":"bash","label":"npm"},{"cmd":"yarn add redux-mock-store","lang":"bash","label":"yarn"},{"cmd":"pnpm add redux-mock-store","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency for Redux applications.","package":"redux","optional":false}],"imports":[{"note":"The primary export is a default export. For CommonJS, use `require('redux-mock-store').default` or rely on transpilers to handle `const { configureStore } = require('redux-mock-store')`.","wrong":"const { configureStore } = require('redux-mock-store')","symbol":"configureStore","correct":"import configureStore from 'redux-mock-store'"}],"quickstart":{"code":"import configureStore from 'redux-mock-store';\nimport thunk from 'redux-thunk';\n\n// Mock fetch for demonstration purposes in a Node.js environment\nglobal.fetch = async (url) => {\n  if (url === '/users.json') {\n    return {\n      json: async () => ([{ id: 1, name: 'Test User' }]),\n      ok: true,\n      status: 200\n    };\n  }\n  throw new Error('Unknown URL: ' + url);\n};\n\nconst middlewares = [thunk]; // Add your Redux middleware\nconst mockStore = configureStore(middlewares);\n\n// Define a simple action creator (would be imported in a real app)\nconst FETCH_DATA_SUCCESS = 'FETCH_DATA_SUCCESS';\nfunction success(data) {\n  return {\n    type: FETCH_DATA_SUCCESS,\n    payload: data\n  };\n}\n\n// Define an async action creator (e.g., using redux-thunk)\nfunction fetchData() {\n  return (dispatch) => {\n    // Simulate an async operation, e.g., an API call\n    return fetch('/users.json')\n      .then(response => response.json())\n      .then(data => dispatch(success(data)));\n  };\n}\n\n// Example test using a common testing framework (like Jest)\ndescribe('redux-mock-store with async actions', () => {\n  it('should dispatch a success action after fetching data', async () => {\n    const store = mockStore({}); // Initialize mock store with an empty initial state\n\n    // Dispatch the async action and await its completion\n    await store.dispatch(fetchData());\n\n    // Retrieve all dispatched actions from the mock store\n    const actions = store.getActions();\n\n    // Assertions on the dispatched actions\n    expect(actions.length).toEqual(1);\n    expect(actions[0].type).toEqual(FETCH_DATA_SUCCESS);\n    expect(actions[0].payload).toEqual([{ id: 1, name: 'Test User' }]);\n\n    console.log('Successfully tested async action dispatch:', actions);\n  });\n});","lang":"javascript","description":"Demonstrates how to test asynchronous Redux actions and middleware (like `redux-thunk`) by initializing a mock store and asserting on the captured dispatched actions."},"warnings":[{"fix":"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.","message":"The `redux-mock-store` package, particularly its `configureStore` method, has been officially deprecated since version 1.5.5 by the Redux team. The recommended testing approach for Redux applications is now to use a real Redux store to verify observable state changes rather than solely focusing on dispatched actions.","severity":"breaking","affected_versions":">=1.5.5"},{"fix":"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.","message":"The `redux-mock-store` intentionally does not run reducers or update its internal state when actions are dispatched. Assertions made on `store.getState()` after dispatching actions will always reflect the `initialState` provided during store creation.","severity":"gotcha","affected_versions":"*"},{"fix":"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.","message":"The approach of testing Redux logic with a mock store that only captures actions, as offered by `redux-mock-store`, is now considered a suboptimal testing practice by the Redux team. This method can lead to brittle tests and a disconnect from the actual application behavior.","severity":"deprecated","affected_versions":">=1.5.5"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"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`.","cause":"Actions were dispatched but not captured, often due to improper asynchronous handling or not calling `store.getActions()` after the async operation completes.","error":"Expected received actions to equal [...], but actual actions were empty array or incorrect."},{"fix":"For ESM, use `import configureStore from 'redux-mock-store'`. For CommonJS, use `const configureStore = require('redux-mock-store').default`.","cause":"This usually indicates an incorrect import statement, particularly when mixing CommonJS `require` with ESM `import` semantics or attempting to destructure a default export.","error":"TypeError: configureStore is not a function"}],"ecosystem":"npm","meta_description":null}