redux-mock-store
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -17,6 +17,6 @@ 'use strict'; | ||
function configureStore() { | ||
var middlewares = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; | ||
var middlewares = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
return function mockStore() { | ||
var _getState = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var _getState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -23,0 +23,0 @@ function mockStoreWithoutMiddleware() { |
The MIT License (MIT) | ||
Copyright (c) 2015 Arnaud Benard | ||
Copyright (c) 2017 Arnaud Benard | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
{ | ||
"name": "redux-mock-store", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -0,1 +1,3 @@ | ||
# 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) | ||
@@ -7,10 +9,4 @@ | ||
# redux-mock-store | ||
A mock store for testing your redux async action creators and middleware. The mock store will create an array of dispatched actions which serve as an action log for tests. | ||
A mock store for testing your redux async action creators and middleware. The mock store will store the dispatched actions in an array to be used in your tests. | ||
## Old version documentation (`< 1.x.x`) | ||
https://github.com/arnaudbenard/redux-mock-store/blob/v0.0.6/README.md | ||
## Install | ||
@@ -21,68 +17,13 @@ | ||
``` | ||
## Documentation | ||
## How to use | ||
You can see the latest documentation [here](http://arnaudbenard.com/redux-mock-store/). | ||
```js | ||
### Old version (`< 1.x.x`) | ||
// actions.test.js | ||
https://github.com/arnaudbenard/redux-mock-store/blob/v0.0.6/README.md | ||
import configureStore from 'redux-mock-store' | ||
import thunk from 'redux-thunk' | ||
const middlewares = [thunk] // add your middlewares like `redux-thunk` | ||
const mockStore = configureStore(middlewares) | ||
// Test example with mocha and expect | ||
it('should dispatch action', () => { | ||
const initialState = {} | ||
const addTodo = { type: 'ADD_TODO' } | ||
const store = mockStore(initialState) | ||
store.dispatch(addTodo) | ||
const actions = store.getActions() | ||
expect(actions).toEqual([addTodo]) | ||
}); | ||
// Promise test example with mocha and expect | ||
it('should execute promise', () => { | ||
function success() { | ||
return { | ||
type: 'FETCH_DATA_SUCCESS' | ||
} | ||
} | ||
function fetchData () { | ||
return dispatch => { | ||
return fetch('/users.json') // Some async action with promise | ||
.then(() => dispatch(success())) | ||
}; | ||
} | ||
const store = mockStore({}) | ||
// Return the promise | ||
return store.dispatch(fetchData()) | ||
.then(() => { | ||
expect(store.getActions()[0]).toEqual(success()) | ||
}) | ||
}) | ||
``` | ||
## API | ||
``` | ||
- configureStore(middlewares?: Array) => mockStore: Function | ||
- mockStore(getState?: Object,Function) => store: Function | ||
- store.dispatch(action) => action | ||
- store.getState() => state: Object | ||
- store.getActions() => actions: Array | ||
- store.clearActions() | ||
- store.subscribe(callback: Function) => unsubscribe: Function | ||
- store.replaceReducer(nextReducer: Function) | ||
``` | ||
## License | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
9557
28