Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

redux-mock-store

> 编程语言
Open source

A mock store for testing Redux async action creators and middleware.

2.5K stars0 likes2 views
WebsiteGitHub

About

A mock store for testing Redux async action creators and middleware.

Deprecation notice

The Redux team does not recommend testing using this library. Instead, see our docs for recommended practices, using a real store.

Testing with a mock store leads to potentially confusing behaviour, such as state not updating when actions are dispatched. Additionally, it's a lot less useful to assert on the actions dispatched rather than the observable state changes.

You can test the entire combination of action creators, reducers, and selectors in a single test, for example:

javascript
it('should add a todo', () => {
  const store = makeStore() // a user defined reusable store factory

  store.dispatch(addTodo('Use Redux'))

  expect(selectTodos(store.getState())).toEqual([
    { text: 'Use Redux', completed: false }
  ])
})

This avoids common pitfalls of testing each of these in isolation, such as mocked state shape becoming out of sync with the actual application.

redux-mock-store

A mock store for testing Redux async action creators and middleware. The mock store will create an array of dispatched actions which serve as an action log for tests.

Please note that this library is designed to test the action-related logic, not the reducer-related one. In other words, it does not update the Redux store. If you want a complex test combining actions and reducers together, take a look at other libraries (e.g., redux-actions-assertions). Refer to issue #71 for more details.

Install

bash
npm install redux-mock-store --save-dev

Or

bash
yarn add redux-mock-store --dev

Usage

Synchronous actions

The simplest usecase is for synchronous actions. In this example, we will test if the addTodo action returns the right payload. redux-mock-store saves all the dispatched actions inside the store instance. You can get all the actions by calling store.getActions(). Finally, you can use any assertion library to test the payload.

…

Asynchronous actions

A common usecase for an asynchronous action is a HTTP request to a server. In order to test those types of actions, you will need to call store.getActions() at the end of the request.

…

API

javascript
configureStore(middlewares?: Array) => mockStore: Function

Configure mock store by applying the middlewares.

javascript
mockStore(getState?: Object,Function) => store: Function

Returns an instance of the configured mock store. If you want to reset your store after every test, you should call this function.

javascript
store.dispatch(action) => action

Dispatches an action through the mock store. The action will be stored in an array inside the instance and executed.

javascript
store.getState() => state: Object

Returns the state of the mock store.

javascript
store.getActions() => actions: Array

Returns the actions of the mock store.

javascript
store.clearActions()

Clears the stored actions.

javascript
store.subscribe(callback: Function) => unsubscribe: Function

Subscribe to the store.

javascript
store.replaceReducer(nextReducer: Function)

Follows the Redux API.

Old version (< 1.x.x)

https://github.com/arnaudbenard/redux-mock-store/blob/v0.0.6/README.md

Versions

The following versions are exposed by redux-mock-store from the package.json:

  • main: commonJS Version
  • module/js:next: ES Module Version
  • browser : UMD version

License

The MIT License

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptjavascriptreduxtest

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言