Merge pull request #232 from skovhus/port-redux-sanity-check

Add error on undefined action type
This commit is contained in:
Dan Abramov 2016-02-02 17:30:06 +00:00
commit f1ecc9d812
2 changed files with 14 additions and 0 deletions

View File

@ -16,6 +16,12 @@ export const ActionTypes = {
*/ */
export const ActionCreators = { export const ActionCreators = {
performAction(action) { 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() }; return { type: ActionTypes.PERFORM_ACTION, action, timestamp: Date.now() };
}, },

View File

@ -176,6 +176,14 @@ describe('instrument', () => {
spy.restore(); 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', () => { it('should return the last non-undefined state from getState', () => {
let storeWithBug = instrument()(createStore)(counterWithBug); let storeWithBug = instrument()(createStore)(counterWithBug);
storeWithBug.dispatch({ type: 'INCREMENT' }); storeWithBug.dispatch({ type: 'INCREMENT' });