1.0.1 • Published 9 years ago
redux-duck-test v1.0.1
Redux Duck Test
Helper functions for testing redux ducks made with redux-duck library.
Installation
npm i -D redux-duck-testAPI
Test action type
import { testType } from 'redux-duck-test';
import { ADD } from '../duck/messages';
const result = testType({
expected: ADD,
actionName: 'ADD',
duckName: 'messages',
moduleName: 'my-app',
});testTypereceive an object with the test specification.- The
expectedkey is your action type. - The
actionNamekey is the name of your action (eg.ADD). - The
duckNamekey is the name of your duck (eg.messages). - The
moduleNamekey is the name of your module (eg.my-app) (optional).
Test action creator
import { testAction } from 'redux-duck-test';
import { ADD, add } from '../duck/messages';
const result = testAction({
actionCreator: add,
payload: {
id: 1,
content: 'hello world!',
},
expected: {
type: ADD,
payload: {
id: 1,
content: 'hello world!',
},
},
});testActionreceive an object with the test specification.- The
actionCreatorkey is the action creator function to test. - The
payloadkey is the payload to send to the action creator. - The
expectedkey is the expected action object.
Test reducer
import { testReducer } from 'redux-duck-test';
import { Map as map } from 'immutable';
import reducer, { add } from '../duck/messages';
const result = testReducer({
reducer,
state: map(),
action: add({
id: 1,
content: 'hello world',
}),
expected: map({
'1': {
id: 1,
content: 'hello world',
},
}),
});testReducerreceive an object with the test specification.- The
reducerkey is the reducer to test. - The
statekey is the initial state passed to the reducer. - The
actionkey is the action to perform in the reducer. - The
expectedkey is the expected next state.