@@ -210,24 +210,24 @@ describe('Utils', () => {
210
210
/ U n e x p e c t e d k e y " b a r " .* c r e a t e S t o r e .* i n s t e a d : " f o o " , " b a z " /
211
211
)
212
212
213
- createStore ( reducer , { bar : 2 , qux : 4 } )
213
+ createStore ( reducer , { bar : 2 , qux : 4 , thud : 5 } )
214
214
expect ( spy . calls [ 1 ] . arguments [ 0 ] ) . toMatch (
215
- / U n e x p e c t e d k e y s " b a r " , " q u x " .* c r e a t e S t o r e .* i n s t e a d : " f o o " , " b a z " /
215
+ / U n e x p e c t e d k e y s " q u x " , " t h u d " .* c r e a t e S t o r e .* i n s t e a d : " f o o " , " b a z " /
216
216
)
217
217
218
218
createStore ( reducer , 1 )
219
219
expect ( spy . calls [ 2 ] . arguments [ 0 ] ) . toMatch (
220
220
/ c r e a t e S t o r e h a s u n e x p e c t e d t y p e o f " N u m b e r " .* k e y s : " f o o " , " b a z " /
221
221
)
222
222
223
- reducer ( { bar : 2 } )
223
+ reducer ( { corge : 2 } )
224
224
expect ( spy . calls [ 3 ] . arguments [ 0 ] ) . toMatch (
225
- / U n e x p e c t e d k e y " b a r " .* r e d u c e r .* i n s t e a d : " f o o " , " b a z " /
225
+ / U n e x p e c t e d k e y " c o r g e " .* r e d u c e r .* i n s t e a d : " f o o " , " b a z " /
226
226
)
227
227
228
- reducer ( { bar : 2 , qux : 4 } )
228
+ reducer ( { fred : 2 , grault : 4 } )
229
229
expect ( spy . calls [ 4 ] . arguments [ 0 ] ) . toMatch (
230
- / U n e x p e c t e d k e y s " b a r " , " q u x " .* r e d u c e r .* i n s t e a d : " f o o " , " b a z " /
230
+ / U n e x p e c t e d k e y s " f r e d " , " g r a u l t " .* r e d u c e r .* i n s t e a d : " f o o " , " b a z " /
231
231
)
232
232
233
233
reducer ( 1 )
@@ -237,5 +237,26 @@ describe('Utils', () => {
237
237
238
238
spy . restore ( )
239
239
} )
240
+
241
+ it ( 'only warns for unexpected keys once' , ( ) => {
242
+ const spy = expect . spyOn ( console , 'error' )
243
+ const foo = ( state = { foo : 1 } ) => state
244
+ const bar = ( state = { bar : 2 } ) => state
245
+
246
+ expect ( spy . calls . length ) . toBe ( 0 )
247
+ const reducer = combineReducers ( { foo, bar } )
248
+ const state = { foo : 1 , bar : 2 , unexpected : 3 }
249
+ reducer ( state , { } )
250
+ reducer ( state , { } )
251
+ reducer ( state , { } )
252
+ reducer ( state , { } )
253
+ expect ( spy . calls . length ) . toBe ( 1 )
254
+ reducer ( { ...state , baz : 5 } , { } )
255
+ reducer ( { ...state , baz : 5 } , { } )
256
+ reducer ( { ...state , baz : 5 } , { } )
257
+ reducer ( { ...state , baz : 5 } , { } )
258
+ expect ( spy . calls . length ) . toBe ( 2 )
259
+ spy . restore ( )
260
+ } )
240
261
} )
241
262
} )
0 commit comments