redux-logic-test - redux-logic test utilities
"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 actions
Installation
redux-logic-test has peerDependencies of redux and redux-logic (which also needs rxjs)
npm install rxjs --savenpm install redux-logic --savenpm install redux --savenpm install redux-logic-test --save-dev
ES6 module import
;
Commonjs
const createMockStore = defaultcreateMockStore;
UMD/CDN use from script tags
The UMD build is mainly used for using in online playgrounds like jsfiddle.
Usage
; // specify as much as necessary for your particular test const store = ; store // use as necessary for your test // when all inflight logic has all completed calls fn + returns promise store - shorthand for storelogicMiddleware storeactions - the actions dispatched use store to clear store - clear storeactions // access the logicMiddleware created for logic/injectedDeps props // use addLogic, mergeNewLogic, replaceLogic, whenComplete, monitor$ storelogicMiddleware
Goals
- simplify the creation of a testing redux store with logicMiddleware attached
- add built-in middleware to track actions that are dispatched
- make it easy to verify the actions that were dispatched
Quick example
;; const fooLogic = ; const logic = fooLogic; // array of logic to use/testconst injectedDeps = // include what is needed for logic API: api // could include mocked API for easy testing; const initialState = {}; // optionally setconst reducer = { return state; }; // optional const store = ; store; // kick off fetchingstore; // other dispatchesstore;
Examples
Live examples
- basic usage - simple use or createMockStore to test actions that were dispatched (jsfiddle)
- async search - async search using createMockStore to setup a test store (jsfiddle)
Full examples
- browser-basic - basic example of using createMockStore to test logic
- nodejs-basic - simple Node.js example using createMockStore via Commonjs to test logic
Get involved
If you have input or ideas or would like to get involved, you may:
- contact me via twitter @jeffbski - http://twitter.com/jeffbski
- open an issue on github to begin a discussion - https://github.com/jeffbski/redux-logic-test/issues
- fork the repo and send a pull request (ideally with tests) - https://github.com/jeffbski/redux-logic-test
Supporters
This project is supported by CodeWinds Training