File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ export function executeReducerBuilderCallback<S>(
140
140
) {
141
141
if ( process . env . NODE_ENV !== 'production' ) {
142
142
/*
143
- to keep the definition by the user in line with actual behavior,
143
+ to keep the definition by the user in line with actual behavior,
144
144
we enforce `addCase` to always be called before calling `addMatcher`
145
145
as matching cases take precedence over matchers
146
146
*/
@@ -159,6 +159,11 @@ export function executeReducerBuilderCallback<S>(
159
159
typeof typeOrActionCreator === 'string'
160
160
? typeOrActionCreator
161
161
: typeOrActionCreator . type
162
+ if ( ! type ) {
163
+ throw new Error (
164
+ '`builder.addCase` cannot be called with an empty action type'
165
+ )
166
+ }
162
167
if ( type in actionsMap ) {
163
168
throw new Error (
164
169
'addCase cannot be called with two reducers for the same action type'
Original file line number Diff line number Diff line change @@ -473,6 +473,24 @@ describe('createReducer', () => {
473
473
`"addCase cannot be called with two reducers for the same action type"`
474
474
)
475
475
} )
476
+
477
+ test ( 'will throw if an empty type is used' , ( ) => {
478
+ const customActionCreator = ( payload : number ) => ( {
479
+ type : 'custom_action' ,
480
+ payload,
481
+ } )
482
+ customActionCreator . type = ""
483
+ expect ( ( ) =>
484
+ createReducer ( 0 , ( builder ) =>
485
+ builder . addCase (
486
+ customActionCreator ,
487
+ ( state , action ) => state + action . payload
488
+ )
489
+ )
490
+ ) . toThrowErrorMatchingInlineSnapshot (
491
+ '"`builder.addCase` cannot be called with an empty action type"'
492
+ )
493
+ } )
476
494
} )
477
495
478
496
describe ( 'builder "addMatcher" method' , ( ) => {
You can’t perform that action at this time.
0 commit comments