diff --git a/src/utils/composeStores.js b/src/utils/composeStores.js index d8c4420546d..11e93860dbf 100644 --- a/src/utils/composeStores.js +++ b/src/utils/composeStores.js @@ -4,8 +4,12 @@ import pick from '../utils/pick'; export default function composeStores(stores) { const finalStores = pick(stores, (val) => typeof val === 'function'); return function Composition(atom = {}, action) { - return mapValues(finalStores, (store, key) => - store(atom[key], action) - ); + return mapValues(finalStores, (store, key) => { + const state = store(atom[key], action); + if (state === undefined) { + throw new Error(`Store ${key} returns undefined. By default store should return original state.`); + } + return state; + }); }; } diff --git a/test/composeStores.spec.js b/test/composeStores.spec.js index 551b275e59a..2a28406f1e1 100644 --- a/test/composeStores.spec.js +++ b/test/composeStores.spec.js @@ -27,5 +27,16 @@ describe('Utils', () => { expect(Object.keys(store({}, {type: 'push'}))).toEqual(['stack']); }); + it('should throw an error if undefined return from store', () => { + const store = composeStores({ + stack: (state = []) => state, + bad: (state= [], action) => { + if (action === 'something') { + return state; + } + } + }); + expect(() => store({}, {type: '@@testType'})).toThrow(); + }); }); });