A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.npmjs.com/package/redux-logic-test below:

redux-logic-test - npm

redux-logic-test - redux-logic test utilities

"Simplifying testing with redux-logic"

Utilities:

Installation

redux-logic-test has peerDependencies of redux and redux-logic (which also needs rxjs)

npm install rxjs --save

npm install redux-logic --save

npm install redux --save

npm install redux-logic-test --save-dev

ES6 module import

import { createMockStore } from 'redux-logic-test';

Commonjs

const createMockStore = require('redux-logic-test').default.createMockStore;

UMD/CDN use from script tags

The UMD build is mainly used for using in online playgrounds like jsfiddle.

<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> 

Usage

  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

Goals Quick example

import { 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: [...] }

  ]);

  

  

 

  

  

  

});

Examples Live examples Full examples Get involved

If you have input or ideas or would like to get involved, you may:

Supporters

This project is supported by CodeWinds Training

License - MIT

RetroSearch 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