diff --git a/modules/store/spec/modules.spec.ts b/modules/store/spec/modules.spec.ts index 5a6690c691..13256ce0a6 100644 --- a/modules/store/spec/modules.spec.ts +++ b/modules/store/spec/modules.spec.ts @@ -119,6 +119,42 @@ describe(`Store Modules`, () => { }); }); + describe(`: With initial state`, () => { + const initialState: RootState = { fruit: 'banana' }; + const reducerMap: ActionReducerMap = { fruit: rootFruitReducer }; + const noopMetaReducer = (r: Function) => (state: any, action: any) => { + return r(state, action); + }; + + const testWithMetaReducers = (metaReducers: any[]) => () => { + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [ + StoreModule.forRoot(reducerMap, { initialState, metaReducers }), + ], + }); + + store = TestBed.get(Store); + }); + + it('should have initial state', () => { + store.take(1).subscribe((s: any) => { + expect(s).toEqual(initialState); + }); + }); + }; + + describe( + 'should add initial state with no meta-reducers', + testWithMetaReducers([]) + ); + + describe( + 'should add initial state with registered meta-reducers', + testWithMetaReducers([noopMetaReducer]) + ); + }); + describe(`: Nested`, () => { @NgModule({ imports: [StoreModule.forFeature('a', featureAReducer)], diff --git a/modules/store/src/state.ts b/modules/store/src/state.ts index ccf9d9b74b..1e0a26fd25 100644 --- a/modules/store/src/state.ts +++ b/modules/store/src/state.ts @@ -35,7 +35,7 @@ export class State extends BehaviorSubject implements OnDestroy { const stateAndAction$: Observable<{ state: any; action: Action; - }> = scan.call(withLatestReducer$, reduceState, initialState); + }> = scan.call(withLatestReducer$, reduceState, { state: initialState }); this.stateSubscription = stateAndAction$.subscribe({ next: ({ state, action }) => {