From 4ceaf3d09ad4db9ad0d43a650ab9d8bf0b62690f Mon Sep 17 00:00:00 2001 From: ksa Date: Mon, 25 Jan 2016 19:40:54 +0100 Subject: [PATCH] Add error on undefined action type --- src/instrument.js | 6 ++++++ test/instrument.spec.js | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/src/instrument.js b/src/instrument.js index 74916126..821f01a3 100644 --- a/src/instrument.js +++ b/src/instrument.js @@ -16,6 +16,12 @@ export const ActionTypes = { */ export const ActionCreators = { performAction(action) { + if (typeof action.type === 'undefined') { + throw new Error( + 'Actions may not have an undefined "type" property. ' + + 'Have you misspelled a constant?' + ); + } return { type: ActionTypes.PERFORM_ACTION, action, timestamp: Date.now() }; }, diff --git a/test/instrument.spec.js b/test/instrument.spec.js index 9db18896..6c6a95aa 100644 --- a/test/instrument.spec.js +++ b/test/instrument.spec.js @@ -176,6 +176,14 @@ describe('instrument', () => { spy.restore(); }); + it('should catch invalid action type', () => { + expect(() => { + store.dispatch({ type: undefined }); + }).toThrow( + /Actions may not have an undefined/ + ); + }); + it('should return the last non-undefined state from getState', () => { let storeWithBug = instrument()(createStore)(counterWithBug); storeWithBug.dispatch({ type: 'INCREMENT' });