Skip to content

Instantly share code, notes, and snippets.

@ruffle1986
Created September 24, 2015 15:50
Show Gist options
  • Save ruffle1986/21091cfbce4e033607ee to your computer and use it in GitHub Desktop.
Save ruffle1986/21091cfbce4e033607ee to your computer and use it in GitHub Desktop.
redux reducer immutability test
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();
});
@ruffle1986
Copy link
Author

Be sure you always return with a new state object from your redux reducer (In case you're not using something like Immutabe.js).

@oroce
Copy link

oroce commented Sep 24, 2015

haha nice trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment