diff --git a/modules/store/spec/integration.spec.ts b/modules/store/spec/integration.spec.ts index 16694a80dd..590c748e79 100644 --- a/modules/store/spec/integration.spec.ts +++ b/modules/store/spec/integration.spec.ts @@ -181,4 +181,49 @@ describe('ngRx Integration spec', () => { expect(currentlyVisibleTodos.length).toBe(0); }); }); + + describe('feature state', () => { + const initialState = { + todos: [ + { + id: 1, + text: 'do things', + completed: false, + }, + ], + visibilityFilter: VisibilityFilters.SHOW_ALL, + }; + + const reducers: ActionReducerMap = { + todos: todos, + visibilityFilter: visibilityFilter, + }; + + const featureInitialState = [{ id: 1, completed: false, text: 'Item' }]; + + it('should initialize properly', () => { + TestBed.configureTestingModule({ + imports: [ + StoreModule.forRoot(reducers, { initialState }), + StoreModule.forFeature('items', todos, { + initialState: featureInitialState, + }), + ], + }); + + const store: Store = TestBed.get(Store); + + let expected = [ + { + todos: initialState.todos, + visibilityFilter: initialState.visibilityFilter, + items: featureInitialState, + }, + ]; + + store.select(state => state).subscribe(state => { + expect(state).toEqual(expected.shift()); + }); + }); + }); }); diff --git a/modules/store/src/reducer_manager.ts b/modules/store/src/reducer_manager.ts index a3f0ee58f8..16054875a1 100644 --- a/modules/store/src/reducer_manager.ts +++ b/modules/store/src/reducer_manager.ts @@ -40,7 +40,7 @@ export class ReducerManager extends BehaviorSubject> }: StoreFeature) { const reducer = typeof reducers === 'function' - ? reducers + ? (state = initialState, action: any) => reducers(state, action) : createReducerFactory(reducerFactory, metaReducers)( reducers, initialState