diff --git a/src/instrument.js b/src/instrument.js index e8c47f0f..00b74f05 100644 --- a/src/instrument.js +++ b/src/instrument.js @@ -336,10 +336,17 @@ function unliftStore(liftedStore, liftReducer) { export default function instrument(monitorReducer = () => null) { return createStore => (reducer, initialState, enhancer) => { function liftReducer(r) { + if (typeof r !== 'function') { + throw new Error('Expected the nextReducer to be a function.'); + } return liftReducerWith(r, initialState, monitorReducer); } const liftedStore = createStore(liftReducer(reducer), undefined, enhancer); + if (liftedStore.liftedStore) { + throw new Error('DevTools instrument shouldn\'t be included more than once. ' + + 'Check your store configuration.'); + } return unliftStore(liftedStore, liftReducer); }; } diff --git a/test/instrument.spec.js b/test/instrument.spec.js index 9db18896..735024af 100644 --- a/test/instrument.spec.js +++ b/test/instrument.spec.js @@ -1,5 +1,5 @@ import expect, { spyOn } from 'expect'; -import { createStore } from 'redux'; +import { createStore, compose } from 'redux'; import instrument, { ActionCreators } from '../src/instrument'; function counter(state = 0, action) { @@ -322,4 +322,15 @@ describe('instrument', () => { expect(importMonitoredLiftedStore.getState()).toEqual(exportedState); }); }); + + it('throws if reducer is not a function', () => { + expect(() => + instrument()(createStore)() + ).toThrow('Expected the nextReducer to be a function.'); + }); + it('throws if there are more than one instrument enhancer included', () => { + expect(() => { + store = createStore(counter, undefined, compose(instrument(), instrument())); + }).toThrow('DevTools instrument shouldn\'t be included more than once. Check your store configuration.'); + }); });