Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Knegusen/redux-test-utils
Library for providing utility functions for testing redux.
https://github.com/Knegusen/redux-test-utils
Last synced: 29 days ago
JSON representation
Library for providing utility functions for testing redux.
- Host: GitHub
- URL: https://github.com/Knegusen/redux-test-utils
- Owner: knegusen
- License: mit
- Created: 2016-07-13T13:25:38.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T10:58:12.000Z (almost 2 years ago)
- Last Synced: 2024-04-29T00:40:21.339Z (8 months ago)
- Language: TypeScript
- Size: 2.02 MB
- Stars: 27
- Watchers: 1
- Forks: 5
- Open Issues: 17
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome-react-redux-saga-boilerplate - redux-test-utils
- awesome-react-redux-saga-boilerplate - redux-test-utils
README
# redux-test-utils [![Build Status](https://travis-ci.org/knegusen/redux-test-utils.svg?branch=master)](https://travis-ci.org/knegusen/redux-test-utils)
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
```js
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
```js
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);
});
});```