@@ -68,6 +68,76 @@ describe('ngRx Store', () => {
68
68
complete : done ,
69
69
} ) ;
70
70
} ) ;
71
+
72
+ function testInitialState ( feature ?: string ) {
73
+ store = TestBed . get ( Store ) ;
74
+ dispatcher = TestBed . get ( ActionsSubject ) ;
75
+
76
+ const actionSequence = '--a--b--c--d--e--f--g' ;
77
+ const stateSequence = 'i-w-----x-----y--z---' ;
78
+ const actionValues = {
79
+ a : { type : INCREMENT } ,
80
+ b : { type : 'OTHER' } ,
81
+ c : { type : RESET } ,
82
+ d : { type : 'OTHER' } , //reproduces https://github.com/ngrx/platform/issues/880 because state is falsey
83
+ e : { type : INCREMENT } ,
84
+ f : { type : INCREMENT } ,
85
+ g : { type : 'OTHER' } ,
86
+ } ;
87
+ const counterSteps = hot ( actionSequence , actionValues ) ;
88
+ counterSteps . subscribe ( action => store . dispatch ( action ) ) ;
89
+
90
+ const counterStateWithString = feature
91
+ ? ( store as any ) . select ( feature , 'counter1' )
92
+ : store . select ( 'counter1' ) ;
93
+
94
+ const counter1Values = { i : 1 , w : 2 , x : 0 , y : 1 , z : 2 } ;
95
+
96
+ expect ( counterStateWithString ) . toBeObservable (
97
+ hot ( stateSequence , counter1Values )
98
+ ) ;
99
+ }
100
+
101
+ it ( 'should reset to initial state when undefined (root ActionReducerMap)' , ( ) => {
102
+ TestBed . configureTestingModule ( {
103
+ imports : [
104
+ StoreModule . forRoot (
105
+ { counter1 : counterReducer } ,
106
+ { initialState : { counter1 : 1 } }
107
+ ) ,
108
+ ] ,
109
+ } ) ;
110
+
111
+ testInitialState ( ) ;
112
+ } ) ;
113
+
114
+ it ( 'should reset to initial state when undefined (feature ActionReducer)' , ( ) => {
115
+ TestBed . configureTestingModule ( {
116
+ imports : [
117
+ StoreModule . forRoot ( { } ) ,
118
+ StoreModule . forFeature ( 'counter1' , counterReducer , {
119
+ initialState : 1 ,
120
+ } ) ,
121
+ ] ,
122
+ } ) ;
123
+
124
+ testInitialState ( ) ;
125
+ } ) ;
126
+
127
+ it ( 'should reset to initial state when undefined (feature ActionReducerMap)' , ( ) => {
128
+ TestBed . configureTestingModule ( {
129
+ imports : [
130
+ StoreModule . forRoot ( { } ) ,
131
+ StoreModule . forFeature (
132
+ 'feature1' ,
133
+ { counter1 : counterReducer } ,
134
+ { initialState : { counter1 : 1 } }
135
+ ) ,
136
+ ] ,
137
+ } ) ;
138
+
139
+ testInitialState ( 'feature1' ) ;
140
+ } ) ;
71
141
} ) ;
72
142
73
143
describe ( 'basic store actions' , ( ) => {
0 commit comments