1.0.0 • Published 3 years ago

@robthefivenine/redux-test-utils v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

redux-test-utils npm.io npm.io

This is a fork of the knegusen/redux-test-utils library, with added support for thunks.

Install

In the terminal execute the following command:

$ npm install @robthefivenine/redux-test-utils --save-dev

or

$ yarn add -D @robthefivenine/redux-test-utils

How to use

createMockStore

import { createMockStore } from '@robthefivenine/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 '@robthefivenine/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);
  });
});