@@ -192,6 +192,7 @@ describe('Utils', () => {
192
192
expect ( spy . mock . calls [ 0 ] [ 0 ] ) . toMatch (
193
193
/ S t o r e d o e s n o t h a v e a v a l i d r e d u c e r /
194
194
)
195
+
195
196
spy . mockClear ( )
196
197
console . error = preSpy
197
198
} )
@@ -265,13 +266,16 @@ describe('Utils', () => {
265
266
const bar = ( state = { bar : 2 } ) => state
266
267
267
268
expect ( spy . mock . calls . length ) . toBe ( 0 )
269
+
268
270
const reducer = combineReducers ( { foo, bar } )
269
271
const state = { foo : 1 , bar : 2 , qux : 3 }
272
+
270
273
reducer ( state , { } )
271
274
reducer ( state , { } )
272
275
reducer ( state , { } )
273
276
reducer ( state , { } )
274
277
expect ( spy . mock . calls . length ) . toBe ( 1 )
278
+
275
279
reducer ( { ...state , baz : 5 } , { } )
276
280
reducer ( { ...state , baz : 5 } , { } )
277
281
reducer ( { ...state , baz : 5 } , { } )
@@ -281,5 +285,72 @@ describe('Utils', () => {
281
285
spy . mockClear ( )
282
286
console . error = preSpy
283
287
} )
288
+
289
+ describe ( 'With Replace Reducers' , function ( ) {
290
+ const foo = ( state = { } ) => state
291
+ const bar = ( state = { } ) => state
292
+ const ACTION = { type : 'ACTION' }
293
+
294
+ it ( 'should return an updated state when additional reducers are passed to combineReducers' , function ( ) {
295
+ const originalCompositeReducer = combineReducers ( { foo } )
296
+ const store = createStore ( originalCompositeReducer )
297
+
298
+ store . dispatch ( ACTION )
299
+
300
+ const initialState = store . getState ( )
301
+
302
+ store . replaceReducer ( combineReducers ( { foo, bar } ) )
303
+ store . dispatch ( ACTION )
304
+
305
+ const nextState = store . getState ( )
306
+ expect ( nextState ) . not . toBe ( initialState )
307
+ } )
308
+
309
+ it ( 'should return an updated state when reducers passed to combineReducers are changed' , function ( ) {
310
+ const baz = ( state = { } ) => state
311
+
312
+ const originalCompositeReducer = combineReducers ( { foo, bar } )
313
+ const store = createStore ( originalCompositeReducer )
314
+
315
+ store . dispatch ( ACTION )
316
+
317
+ const initialState = store . getState ( )
318
+
319
+ store . replaceReducer ( combineReducers ( { baz, bar } ) )
320
+ store . dispatch ( ACTION )
321
+
322
+ const nextState = store . getState ( )
323
+ expect ( nextState ) . not . toBe ( initialState )
324
+ } )
325
+
326
+ it ( 'should return the same state when reducers passed to combineReducers not changed' , function ( ) {
327
+ const originalCompositeReducer = combineReducers ( { foo, bar } )
328
+ const store = createStore ( originalCompositeReducer )
329
+
330
+ store . dispatch ( ACTION )
331
+
332
+ const initialState = store . getState ( )
333
+
334
+ store . replaceReducer ( combineReducers ( { foo, bar } ) )
335
+ store . dispatch ( ACTION )
336
+
337
+ const nextState = store . getState ( )
338
+ expect ( nextState ) . toBe ( initialState )
339
+ } )
340
+
341
+ it ( 'should return an updated state when one of more reducers passed to the combineReducers are removed' , function ( ) {
342
+ const originalCompositeReducer = combineReducers ( { foo, bar } )
343
+ const store = createStore ( originalCompositeReducer )
344
+
345
+ store . dispatch ( ACTION )
346
+
347
+ const initialState = store . getState ( )
348
+
349
+ store . replaceReducer ( combineReducers ( { bar } ) )
350
+
351
+ const nextState = store . getState ( )
352
+ expect ( nextState ) . not . toBe ( initialState )
353
+ } )
354
+ } )
284
355
} )
285
356
} )
0 commit comments