redux-test-utils
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

redux-test-utils Build Status

Test utils to simplify testing of containers in redux.

Install

In the terminal execute the following command:

$ npm install redux-test-utils --save-dev

How to use

createMockStore

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

describe('example', () => {
  it('works', () => {
    const state = 'state';
    const store = createMockStore(state);
    const action = {
      type: 'type',
      data: 'data'
    };
    store.dispatch(action);
    
    expect(store.getAction(action.type)).toEqual(action);
    expect(store.getActions()).toEqual([action]);
    expect(store.isActionDispatched(action)).toBe(true);
    expect(store.isActionTypeDispatched(action.type)).toBe(true);
    expect(store.getState()).toBe(state);
  });
});

createMockDispatch

import { createMockDispatch } from 'redux-test-utils';

describe('example', () => {
  it('works', () => {
    const state = 'state';
    const dispatchMock = createMockDispatch();
    const action = {
      type: 'type',
      data: 'data',
    };
    dispatchMock.dispatch(action);

    expect(dispatchMock.getAction(action.type)).toEqual(action);
    expect(dispatchMock.getActions()).toEqual([action]);
    expect(dispatchMock.isActionDispatched(action)).toBe(true);
    expect(dispatchMock.isActionTypeDispatched(action.type)).toBe(true);
  });
});

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.28,535latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.28,535
1.0.11
1.0.0388
0.3.05,120
0.2.26,248
0.2.1190
0.2.02
0.1.3473
0.1.2223
0.1.12
0.1.02

Package Sidebar

Install

npm i redux-test-utils

Weekly Downloads

21,184

Version

1.0.2

License

MIT

Unpacked Size

8.57 kB

Total Files

12

Last publish

Collaborators

  • knegusen