Created
September 24, 2015 15:50
-
-
Save ruffle1986/21091cfbce4e033607ee to your computer and use it in GitHub Desktop.
redux reducer immutability test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import test from 'ava'; | |
import * as actionTypes from './your-action-types'; | |
import reducer from './your-reducer'; | |
import deepEqual from 'deep-equal'; | |
test('reducer:immutability test', t => { | |
const dummy = {}; | |
for (const action in actionTypes) { | |
if (actionTypes.hasOwnProperty(action)) { | |
const result = reducer(dummy, {type: actionTypes[action]}); | |
t.false(deepEqual(dummy, result, {strict: true})); | |
} | |
} | |
t.end(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Be sure you always return with a new state object from your redux reducer (In case you're not using something like Immutabe.js).