Skip to content

Commit

Permalink
fix(Store): Set initial state for feature modules (#235)
Browse files Browse the repository at this point in the history
Closes #206, #233
  • Loading branch information
brandonroberts authored and MikeRyanDev committed Aug 4, 2017
1 parent 2b1a076 commit 4aec80c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions modules/store/spec/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TodoAppSchema, any> = {
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<any> = TestBed.get(Store);

let expected = [
{
todos: initialState.todos,
visibilityFilter: initialState.visibilityFilter,
items: featureInitialState,
},
];

store.select(state => state).subscribe(state => {
expect(state).toEqual(expected.shift());
});
});
});
});
2 changes: 1 addition & 1 deletion modules/store/src/reducer_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ReducerManager extends BehaviorSubject<ActionReducer<any, any>>
}: StoreFeature<any, any>) {
const reducer =
typeof reducers === 'function'
? reducers
? (state = initialState, action: any) => reducers(state, action)
: createReducerFactory(reducerFactory, metaReducers)(
reducers,
initialState
Expand Down

0 comments on commit 4aec80c

Please sign in to comment.