@@ -310,7 +310,7 @@ describe('frint-store › createStore', function () {
310310 subscription . unsubscribe ( ) ;
311311 } ) ;
312312
313- it ( 'handles combined reducers' , function ( ) {
313+ describe ( 'handles combined reducers' , function ( ) {
314314 function counterReducer ( state = { value : 0 } , action ) {
315315 switch ( action . type ) {
316316 case 'INCREMENT_COUNTER' :
@@ -342,39 +342,104 @@ describe('frint-store › createStore', function () {
342342 color : colorReducer ,
343343 } ) ;
344344
345- const Store = createStore ( {
346- enableLogger : false ,
347- initialState : {
348- counter : {
349- value : 100 ,
345+ it ( 'with given initial state' , function ( ) {
346+ const Store = createStore ( {
347+ enableLogger : false ,
348+ initialState : {
349+ counter : {
350+ value : 100 ,
351+ } ,
352+ color : {
353+ value : 'red'
354+ }
350355 } ,
351- color : {
352- value : 'red'
353- }
354- } ,
355- reducer : rootReducer ,
356+ reducer : rootReducer ,
357+ } ) ;
358+ const store = new Store ( ) ;
359+
360+ const states = [ ] ;
361+ const subscription = store . getState$ ( )
362+ . subscribe ( ( state ) => {
363+ states . push ( state ) ;
364+ } ) ;
365+
366+ store . dispatch ( { type : 'INCREMENT_COUNTER' } ) ;
367+ store . dispatch ( { type : 'INCREMENT_COUNTER' } ) ;
368+ store . dispatch ( { type : 'DECREMENT_COUNTER' } ) ;
369+ store . dispatch ( { type : 'SET_COLOR' , color : 'green' } ) ;
370+
371+ expect ( states ) . to . deep . equal ( [
372+ { counter : { value : 100 } , color : { value : 'red' } } , // initial
373+ { counter : { value : 101 } , color : { value : 'red' } } , // INCREMENT_COUNTER
374+ { counter : { value : 102 } , color : { value : 'red' } } , // INCREMENT_COUNTER
375+ { counter : { value : 101 } , color : { value : 'red' } } , // DECREMENT_COUNTER
376+ { counter : { value : 101 } , color : { value : 'green' } } // SET_COLOR
377+ ] ) ;
378+
379+ subscription . unsubscribe ( ) ;
356380 } ) ;
357- const store = new Store ( ) ;
358381
359- const states = [ ] ;
360- const subscription = store . getState$ ( )
361- . subscribe ( ( state ) => {
362- states . push ( state ) ;
382+ it ( 'with no given initial state' , function ( ) {
383+ const Store = createStore ( {
384+ enableLogger : false ,
385+ reducer : rootReducer ,
363386 } ) ;
387+ const store = new Store ( ) ;
364388
365- store . dispatch ( { type : 'INCREMENT_COUNTER' } ) ;
366- store . dispatch ( { type : 'INCREMENT_COUNTER' } ) ;
367- store . dispatch ( { type : 'DECREMENT_COUNTER' } ) ;
368- store . dispatch ( { type : 'SET_COLOR' , color : 'green' } ) ;
389+ const states = [ ] ;
390+ const subscription = store . getState$ ( )
391+ . subscribe ( ( state ) => {
392+ states . push ( state ) ;
393+ } ) ;
369394
370- expect ( states ) . to . deep . equal ( [
371- { counter : { value : 100 } , color : { value : 'red' } } , // initial
372- { counter : { value : 101 } , color : { value : 'red' } } , // INCREMENT_COUNTER
373- { counter : { value : 102 } , color : { value : 'red' } } , // INCREMENT_COUNTER
374- { counter : { value : 101 } , color : { value : 'red' } } , // DECREMENT_COUNTER
375- { counter : { value : 101 } , color : { value : 'green' } } // SET_COLOR
376- ] ) ;
395+ store . dispatch ( { type : 'INCREMENT_COUNTER' } ) ;
396+ store . dispatch ( { type : 'INCREMENT_COUNTER' } ) ;
397+ store . dispatch ( { type : 'DECREMENT_COUNTER' } ) ;
398+ store . dispatch ( { type : 'SET_COLOR' , color : 'green' } ) ;
377399
378- subscription . unsubscribe ( ) ;
400+ expect ( states ) . to . deep . equal ( [
401+ { counter : { value : 0 } , color : { value : 'blue' } } , // initial
402+ { counter : { value : 1 } , color : { value : 'blue' } } , // INCREMENT_COUNTER
403+ { counter : { value : 2 } , color : { value : 'blue' } } , // INCREMENT_COUNTER
404+ { counter : { value : 1 } , color : { value : 'blue' } } , // DECREMENT_COUNTER
405+ { counter : { value : 1 } , color : { value : 'green' } } // SET_COLOR
406+ ] ) ;
407+
408+ subscription . unsubscribe ( ) ;
409+ } ) ;
410+
411+ it ( 'with partially given initial state for certain reducers' , function ( ) {
412+ const Store = createStore ( {
413+ enableLogger : false ,
414+ initialState : {
415+ counter : {
416+ value : 100 ,
417+ } ,
418+ } ,
419+ reducer : rootReducer ,
420+ } ) ;
421+ const store = new Store ( ) ;
422+
423+ const states = [ ] ;
424+ const subscription = store . getState$ ( )
425+ . subscribe ( ( state ) => {
426+ states . push ( state ) ;
427+ } ) ;
428+
429+ store . dispatch ( { type : 'INCREMENT_COUNTER' } ) ;
430+ store . dispatch ( { type : 'INCREMENT_COUNTER' } ) ;
431+ store . dispatch ( { type : 'DECREMENT_COUNTER' } ) ;
432+ store . dispatch ( { type : 'SET_COLOR' , color : 'green' } ) ;
433+
434+ expect ( states ) . to . deep . equal ( [
435+ { counter : { value : 100 } , color : { value : 'blue' } } , // initial
436+ { counter : { value : 101 } , color : { value : 'blue' } } , // INCREMENT_COUNTER
437+ { counter : { value : 102 } , color : { value : 'blue' } } , // INCREMENT_COUNTER
438+ { counter : { value : 101 } , color : { value : 'blue' } } , // DECREMENT_COUNTER
439+ { counter : { value : 101 } , color : { value : 'green' } } // SET_COLOR
440+ ] ) ;
441+
442+ subscription . unsubscribe ( ) ;
443+ } ) ;
379444 } ) ;
380445} ) ;
0 commit comments