Skip to content

Commit f1ecc9d

Browse files
committed
Merge pull request #232 from skovhus/port-redux-sanity-check
Add error on undefined action type
2 parents a7e1221 + 4ceaf3d commit f1ecc9d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/instrument.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ export const ActionTypes = {
1616
*/
1717
export const ActionCreators = {
1818
performAction(action) {
19+
if (typeof action.type === 'undefined') {
20+
throw new Error(
21+
'Actions may not have an undefined "type" property. ' +
22+
'Have you misspelled a constant?'
23+
);
24+
}
1925
return { type: ActionTypes.PERFORM_ACTION, action, timestamp: Date.now() };
2026
},
2127

test/instrument.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ describe('instrument', () => {
176176
spy.restore();
177177
});
178178

179+
it('should catch invalid action type', () => {
180+
expect(() => {
181+
store.dispatch({ type: undefined });
182+
}).toThrow(
183+
/Actions may not have an undefined/
184+
);
185+
});
186+
179187
it('should return the last non-undefined state from getState', () => {
180188
let storeWithBug = instrument()(createStore)(counterWithBug);
181189
storeWithBug.dispatch({ type: 'INCREMENT' });

0 commit comments

Comments
 (0)