New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

redux-mock-store

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-mock-store - npm Package Compare versions

Comparing version 1.5.1 to 1.5.3

lib/index.js

27

package.json
{
"name": "redux-mock-store",
"version": "1.5.1",
"version": "1.5.3",
"description": "A mock store for testing your redux async action creators and middleware",
"main": "dist/index-cjs.js",
"module": "dist/index-es.js",
"js:next": "dist/index-es.js",
"browser": "dist/index.min.js",
"main": "lib/index.js",
"scripts": {
"prepublish": "rimraf lib && rimraf dist && npm run build",
"build:cjs": "cross-env BABEL_ENV=es NODE_ENV=production rollup -f cjs -c -i src/index.js -o dist/index-cjs.js",
"build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -f umd -c -i src/index.js -o dist/index-umd.js",
"build:umd:min": "cross-env BABEL_ENV=es NODE_ENV=production rollup -f umd -c -i src/index.js -o dist/index-umd.min.js",
"build:es": "cross-env BABEL_ENV=es NODE_ENV=development rollup -f es -c -i src/index.js -o dist/index-es.js",
"build": "npm run build:cjs && npm run build:umd && npm run build:umd:min && npm run build:es",
"prepublish": "rimraf lib && babel src --out-dir lib",
"lint": "standard src/*.js test/*.js",

@@ -33,5 +25,3 @@ "pretest": "npm run lint",

"babel-core": "^6.13.2",
"babel-plugin-external-helpers": "^6.22.0",
"babel-preset-env": "^1.6.1",
"cross-env": "^5.0.1",
"babel-preset-es2015": "^6.13.2",
"expect": "^1.12.2",

@@ -42,8 +32,2 @@ "mocha": "^2.3.3",

"rimraf": "^2.4.3",
"rollup": "^0.45.1",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-replace": "^1.1.1",
"rollup-plugin-uglify": "^2.0.1",
"sinon": "^1.17.2",

@@ -54,6 +38,3 @@ "standard": "^7.1.2"

"lodash.isplainobject": "^4.0.6"
},
"peerDependencies": {
"redux": "*"
}
}

@@ -13,113 +13,6 @@ # redux-mock-store [![Circle CI](https://circleci.com/gh/arnaudbenard/redux-mock-store/tree/master.svg?style=svg)](https://circleci.com/gh/arnaudbenard/redux-mock-store/tree/master)

```
## Documentation
## Usage
You can see the latest documentation [here](http://arnaudbenard.com/redux-mock-store/).
### Synchronous action
The simplest usecase is for the 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 action by calling `store.getActions()`. Finally, you can use any assertion library to test the payload.
```js
import configureStore from 'redux-mock-store'
const middlewares = []
const mockStore = configureStore(middlewares)
// You would import the action from your codebase in a real scenario
const addTodo = () => ({ type: 'ADD_TODO' })
it('should dispatch action', () => {
// Initialize mockstore with empty state
const initialState = {}
const store = mockStore(initialState)
// Dispatch the action
store.dispatch(addTodo())
// Test if your store dispatched the expected actions
const actions = store.getActions()
const expectedPayload = { type: 'ADD_TODO' }
expect(actions).toEqual([expectedPayload])
})
```
### Asynchronous action
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.
```js
import configureStore from 'redux-mock-store'
import thunk from 'redux-thunk'
const middlewares = [thunk] // add your middlewares like `redux-thunk`
const mockStore = configureStore(middlewares)
// You would import the action from your codebase in a real scenario
function success() {
return {
type: 'FETCH_DATA_SUCCESS'
}
}
function fetchData () {
return dispatch => {
return fetch('/users.json') // Some async action with promise
.then(() => dispatch(success()))
};
}
it('should execute fetch data', () => {
const store = mockStore({})
// Return the promise
return store.dispatch(fetchData())
.then(() => {
const actions = store.getActions()
expect(actions[0]).toEqual(success())
})
})
```
### API
```js
configureStore(middlewares?: Array) => mockStore: Function
```
Configure mock store by applying the middlewares
```js
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.
```js
store.dispatch(action) => action
```
Dispatches an action through the mock store. The action will be stored in an array inside the instance and executed.
```js
store.getState() => state: Object
```
Returns the state of the mock store
```js
store.getActions() => actions: Array
```
Returns the actions of the mock store
```js
store.clearActions()
```
Clears the stored actions
```js
store.subscribe(callback: Function) => unsubscribe: Function
```
Subscribe to the store
```js
store.replaceReducer(nextReducer: Function)
```
Follows the redux API
### Old version (`< 1.x.x`)

@@ -133,1 +26,3 @@

MIT
<a href="https://app.codesponsor.io/link/jxMtyJ1U2FXauYmvU37ewrmE/arnaudbenard/redux-mock-store" rel="nofollow"><img src="https://app.codesponsor.io/embed/jxMtyJ1U2FXauYmvU37ewrmE/arnaudbenard/redux-mock-store.svg" style="width: 888px; height: 68px;" alt="Sponsor" /></a>
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc