{"id":15374,"library":"redux-logic-test","title":"Redux Logic Test Utilities","description":"redux-logic-test provides testing utilities specifically designed to simplify the integration and unit testing of Redux Logic modules. It offers a `createMockStore` function that sets up a Redux store with a `redux-logic` middleware instance, allowing developers to easily inject logic, initial state, and mocked dependencies (like an API service) for isolated testing. The utility also includes built-in action tracking and a `whenComplete` helper to ensure all asynchronous logic operations have finished before assertions are made. The current stable version is 2.0.0, which primarily relaxed peer dependency constraints for Redux and Redux Logic without introducing API breaking changes. Release cadence is tied to updates in its core dependencies, `redux` and `redux-logic`, aiming for compatibility rather than frequent feature additions. Its key differentiator is its direct integration with `redux-logic`'s specific patterns, offering a more tailored testing experience than generic Redux testing utilities.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/jeffbski/redux-logic-test","tags":["javascript","redux-logic","test","testing","utilities","mock","store"],"install":[{"cmd":"npm install redux-logic-test","lang":"bash","label":"npm"},{"cmd":"yarn add redux-logic-test","lang":"bash","label":"yarn"},{"cmd":"pnpm add redux-logic-test","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for the underlying Redux store functionality.","package":"redux","optional":false},{"reason":"Peer dependency, this library provides test utilities specifically for redux-logic.","package":"redux-logic","optional":false},{"reason":"Indirectly required as a peer dependency of redux-logic.","package":"rxjs","optional":false}],"imports":[{"note":"createMockStore is a named export, not a default export.","wrong":"import createMockStore from 'redux-logic-test';","symbol":"createMockStore","correct":"import { createMockStore } from 'redux-logic-test';"},{"note":"While older versions or some transpilation might result in `default.createMockStore`, the direct named import is the correct CJS pattern for many modern setups.","wrong":"const createMockStore = require('redux-logic-test').default.createMockStore;","symbol":"createMockStore (CommonJS)","correct":"const { createMockStore } = require('redux-logic-test');"},{"note":"For TypeScript, import types explicitly to avoid bundling unnecessary runtime code.","symbol":"Type (if using TypeScript)","correct":"import type { MockStore } from 'redux-logic-test';"}],"quickstart":{"code":"import { createMockStore } from 'redux-logic-test';\nimport { createLogic } from 'redux-logic';\n\nconst API = {\n  get: (url) => Promise.resolve({ data: `Fetched data from ${url}` })\n};\n\nconst fooLogic = createLogic({\n  type: 'FOO',\n  process({ API, getState, action }, dispatch, done) {\n    API.get(`/api/${action.payload}`)\n      .then(results => {\n        dispatch({ type: 'FOO_SUCCESS', payload: results.data });\n      })\n      .catch(error => {\n        dispatch({ type: 'FOO_FAILURE', payload: error.message });\n      })\n      .finally(() => done());\n  }\n});\n\nconst logic = [fooLogic];\nconst injectedDeps = { API };\n\nconst initialState = { some: 'state' };\nconst reducer = (state = initialState, action) => {\n  switch(action.type) {\n    case 'FOO_SUCCESS': return { ...state, lastFetch: action.payload };\n    default: return state;\n  }\n};\n\nasync function runTest() {\n  const store = createMockStore({\n    initialState,\n    reducer,\n    logic,\n    injectedDeps\n  });\n\n  store.dispatch({ type: 'FOO', payload: 'item123' });\n  store.dispatch({ type: 'BAR' }); // Will be tracked but not processed by logic\n\n  await store.whenComplete(); // Wait for fooLogic to finish\n\n  console.log('Final State:', store.getState());\n  console.log('Dispatched Actions:', store.actions);\n\n  // Example assertions (in a real test framework like Jest)\n  // expect(store.getState().lastFetch).toBe('Fetched data from /api/item123');\n  // expect(store.actions).toEqual([\n  //   { type: 'FOO', payload: 'item123' },\n  //   { type: 'BAR' },\n  //   { type: 'FOO_SUCCESS', payload: 'Fetched data from /api/item123' }\n  // ]);\n}\n\nrunTest();","lang":"javascript","description":"This example demonstrates setting up a mock Redux store with `redux-logic-test`, including a sample logic, mocked dependencies, initial state, and reducer. It dispatches actions, waits for logic completion, and logs the resulting state and dispatched actions for verification."},"warnings":[{"fix":"Review and update your project's 'redux' and 'redux-logic' peer dependencies to satisfy the new ranges specified in redux-logic-test@2.0.0. Run `npm install` or `yarn install` to ensure correct versions are resolved.","message":"Version 2.0.0 relaxed peer dependency constraints for 'redux' and 'redux-logic'. While not a direct API breaking change in 'redux-logic-test', ensure your project's `redux` and `redux-logic` versions are compatible with the newly allowed ranges, especially if upgrading from a version that had stricter requirements. This could lead to runtime errors if older versions of peer dependencies are used that are not compatible with the relaxed range.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure `npm install rxjs redux redux-logic --save` (or `--save-dev` if only for testing) is run, in addition to `npm install redux-logic-test --save-dev`.","message":"It is crucial to install `rxjs`, `redux`, and `redux-logic` as peer dependencies. `redux-logic-test` itself is a dev dependency, but its functionality relies heavily on these runtime dependencies being present in your project. Forgetting to install `rxjs` is a common oversight as it's an indirect dependency of `redux-logic`.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Wrap your assertions in an async block and await `store.whenComplete()` before verifying state or actions: `await store.whenComplete(); expect(store.actions).toEqual([...]);`","message":"Always call `store.whenComplete()` (or `store.logicMiddleware.whenComplete()`) and `await` it in async tests to ensure all asynchronous logic operations have finished before making assertions. Failing to do so can lead to flaky tests where assertions run before the logic has had a chance to dispatch final actions or update state.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure 'redux-logic' is correctly installed in your project: `npm install redux-logic --save`.","cause":"redux-logic is not installed or incorrectly resolved, which redux-logic-test depends on to create the middleware.","error":"TypeError: Cannot read properties of undefined (reading 'createLogicMiddleware')"},{"fix":"Install 'rxjs' in your project: `npm install rxjs --save`.","cause":"rxjs, a peer dependency of redux-logic, is missing or incorrectly resolved.","error":"TypeError: Cannot read properties of undefined (reading 'Observable')"},{"fix":"Install 'redux' in your project: `npm install redux --save`.","cause":"The 'redux' package, a peer dependency of redux-logic-test, is missing.","error":"Error: Peer dependency 'redux' is not installed."},{"fix":"Ensure your project is configured for either ES Modules (using `import`) or CommonJS (using `require`). If using ES Modules, ensure your `package.json` has `\"type\": \"module\"` and use `import { createMockStore } from 'redux-logic-test';`. If using CommonJS, use `const { createMockStore } = require('redux-logic-test');`.","cause":"Attempting to use CommonJS `require()` syntax in an ES Modules environment without proper configuration, or vice-versa with `import`.","error":"ReferenceError: require is not defined"}],"ecosystem":"npm"}