0.7.1 • Published 6 years ago

describe-redux v0.7.1

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
6 years ago

npm install describe-redux

describeRedux() is a substitute for regular describe(). Under the hood it creates a redux store and passes an object containing the store, it's state getter and bound actions to the callback.

In the examples the typescript-fsa lib is used to create actions, but it should not make any difference.

It has the following signature:

function describeRedux<S extends {}, A extends ActionCreatorsMapObject>(
  // a test suite description (similar to `describe()`)
  description: string,
  
  // a reducer
  reducer: Reducer<S>,
  
  // an initial state
  initialState: S,
  
  // actions (of type ActionCreatorsMapObject which is an object)
  actions: A,
  
  // callback which received an argument `redux` which allow to access the store
  callback: (redux: DescribeReduxContext<S, A>) => void
): void;

The callback argument has the following type

type DescribeReduxContext<Sextends {}, A extends ActionCreatorsMapObject> = {
  // redux store
  store: Store<S>;
  
  // state getter (same as store.getState())
  state: Readonly<S>;
  
  // bound actions
  actions: A;
};

A full example can be found under the examples folder

import { expect } from 'chai';
import { describeRedux } from 'describe-redux';
import * as actions from './actions';
import { initialState, reducer } from './store';


describe('Test store', () => {

  // with initial state
  describeRedux(
    `action ${actions.addItem.type}`,
    reducer,
    initialState,
    actions,
    redux => {

      it('should add item', () => {
        redux.actions.addItem({id: 'test-id'});
        expect(redux.state.items).to.eql(['test-id']);
      });

  });

});
0.7.1

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago