diff --git a/modules/store/spec/fixtures/foos.ts b/modules/store/spec/fixtures/foos.ts new file mode 100644 index 0000000000..308d7e4405 --- /dev/null +++ b/modules/store/spec/fixtures/foos.ts @@ -0,0 +1,10 @@ +export const ADD_FOO = 'ADD_FOO'; + +export function foos(state: string[] = [], { type, payload }: any): string[] { + switch (type) { + case ADD_FOO: + return [...state, payload]; + default: + return state; + } +} diff --git a/modules/store/spec/integration.spec.ts b/modules/store/spec/integration.spec.ts index 16694a80dd..2841d7a652 100644 --- a/modules/store/spec/integration.spec.ts +++ b/modules/store/spec/integration.spec.ts @@ -27,6 +27,8 @@ import { COMPLETE_ALL_TODOS, } from './fixtures/todos'; +import { foos } from './fixtures/foos'; + interface Todo { id: number; text: string; @@ -39,6 +41,54 @@ interface TodoAppSchema { } describe('ngRx Integration spec', () => { + 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 = ['bar']; + + it('should initialize properly', () => { + TestBed.configureTestingModule({ + imports: [ + StoreModule.forRoot(reducers, { initialState }), + StoreModule.forFeature('foos', foos, { + initialState: featureInitialState, + }), + ], + }); + const store: Store = TestBed.get(Store); + + let expected = [ + { + todos: [ + { + id: 1, + text: 'do things', + completed: false, + }, + ], + visibilityFilter: 'SHOW_ALL', + foos: ['bar'], + }, + ]; + store.select(state => state).subscribe(state => { + expect(state).toEqual(expected.shift()); + }); + expect(expected.length).toBe(0); + }); + }); describe('todo integration spec', function() { let store: Store; let state: State;