{"library":"redux-test-utils","title":"Redux Mocking Test Utilities","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install redux-test-utils"],"cli":null},"imports":["import { createMockStore } from 'redux-test-utils';","import { createMockDispatch } from 'redux-test-utils';","import type { MockStore } from 'redux-test-utils';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { createMockStore } from 'redux-test-utils';\n\ndescribe('Redux Mock Store Example', () => {\n  const initialState = { user: { name: 'John Doe', id: '123' }, settings: { theme: 'dark' } };\n\n  it('should correctly capture dispatched actions and maintain state', () => {\n    const store = createMockStore(initialState);\n    const loginAction = {\n      type: 'USER_LOGIN',\n      payload: { username: 'jdoe' }\n    };\n    const themeChangeAction = {\n      type: 'SET_THEME',\n      payload: 'light'\n    };\n\n    store.dispatch(loginAction);\n    store.dispatch(themeChangeAction);\n    \n    expect(store.getAction(loginAction.type)).toEqual(loginAction);\n    expect(store.getActions()).toEqual([loginAction, themeChangeAction]);\n    expect(store.isActionDispatched(loginAction)).toBe(true);\n    expect(store.isActionTypeDispatched('SET_THEME')).toBe(true);\n    expect(store.getState()).toBe(initialState);\n  });\n\n  it('should reset actions when a new mock store is created', () => {\n    const store1 = createMockStore({});\n    store1.dispatch({ type: 'TEST_ACTION_1' });\n    expect(store1.getActions().length).toBe(1);\n\n    const store2 = createMockStore({});\n    expect(store2.getActions().length).toBe(0);\n  });\n});","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}