redux-test-utils provides a focused set of utilities designed to simplify the testing of Redux-connected components and logic. It offers `createMockStore` and `createMockDispatch` functions, which produce mock objects that mimic the behavior of a Redux store and dispatch function, respectively. These mocks capture dispatched actions, allowing developers to easily assert against action types, payloads, and dispatch order using intuitive methods like `getAction`, `getActions`, `isActionDispatched`, and `isActionTypeDispatched`. The library is currently at version 1.0.2, with its 1.0.0 release marking a complete rewrite in TypeScript, enhancing type safety and developer experience. While there isn't a strict release cadence, updates address compatibility and improvements. Its key differentiator lies in its Redux-specific API, which offers a more streamlined and less verbose testing approach compared to general-purpose mocking libraries for Redux scenarios.
npm install redux-test-utilsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a mock Redux store, dispatch actions, and use the utility methods to assert on the dispatched actions and the store's state.
Ensure your project uses a bundler or test runner that correctly handles ES Modules and TypeScript. Update TypeScript configuration if necessary to include the library's types.
Install 'redux' with `npm install redux@^4.0.0` or `yarn add redux@^4.0.0`.
Understand the scope of `redux-test-utils` for simple action/state assertions. For middleware, use `redux-mock-store`; for full integration, set up a real store.
Ensure you are using `import { createMockStore } from 'redux-test-utils';`. If in a Node.js CJS environment, configure your test runner (e.g., Jest) to transpile ES modules, or use an ESM-compatible setup.Install the package using `npm install redux-test-utils --save-dev` or `yarn add redux-test-utils --dev`. Verify your `tsconfig.json` (if applicable) and build tool configurations.