"Simplifying testing with redux-logic"
Utilities:
createMockStore
- create a redux-logic middleware and a redux store, attaching the middleware and providing a mechanism to verify the dispatched actionsredux-logic-test has peerDependencies of redux and redux-logic (which also needs rxjs)
ES6 module importnpm install rxjs --save
npm install redux-logic --save
npm install redux --save
npm install redux-logic-test --save-dev
Commonjsimport { createMockStore } from 'redux-logic-test';
UMD/CDN use from script tagsconst createMockStore = require('redux-logic-test').default.createMockStore;
The UMD build is mainly used for using in online playgrounds like jsfiddle.
Usage<script src="https://npmcdn.com/redux@%5E3.6.0/dist/redux.min.js"></script>
<script src="https://unpkg.com/redux-logic@%5E0.11.6/dist/redux-logic.min.js"></script>
<script src="https://unpkg.com/redux-logic-test@%5E1.0.1/dist/redux-logic-test.min.js"></script>
<script type="text/javascript">
  const { createLogic } = ReduxLogic;
  const { createMockStore } = ReduxLogicTest;
 Â
</script>Â
Goals  import { createMockStore } from 'redux-logic-test';
Â
 Â
  const store = createMockStore({
    initialState: optionalObject,
    reducer: optionalFn,Â
    logic: optionalLogic,Â
    injectedDeps: optionalObject,Â
    middleware: optionalArrÂ
  });
Â
  store.dispatch(...)Â
Â
 Â
  store.whenComplete(fn) - shorthand for store.logicMiddleware.whenComplete(fn)
Â
  store.actions - the actions dispatched, use store.resetActions() to clear
  store.resetActions() - clear store.actions
Â
 Â
 Â
  store.logicMiddleware
Examples Live examplesimport { createMockStore } from 'redux-logic-test';
import { createLogic } from 'redux-logic';
Â
const fooLogic = createLogic({
  type: 'FOO',
  process({ API, getState, action }, dispatch, done) {
    API.get(...)
      .then(results => {
        dispatch({ type: 'FOO_SUCCESS', payload: results });
        done();
      });
  }
});
Â
const logic = [fooLogic];Â
const injectedDeps = {Â
  API: apiÂ
};
Â
const initialState = {};Â
const reducer = (state, action) => { return state; };Â
Â
const store = createMockStore({
  initialState,
  reducer,
  logic,
  injectedDeps
});
Â
store.dispatch({Â type:Â 'FOO'Â });Â
store.dispatch({Â type:Â 'BAR'Â });Â
store.whenComplete(()Â =>Â {Â
  expect(store.getState()).toEqual({...});
  expect(store.actions).toEqual([
    { type: 'FOO' },
    { type: 'BAR' },
    { type: 'FOO_SUCCESS', payload: [...] }
  ]);
 Â
 Â
Â
 Â
 Â
 Â
});
If you have input or ideas or would like to get involved, you may:
This project is supported by CodeWinds Training
License - MITRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4