Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Store): Set initial state for feature modules #235

Merged
merged 1 commit into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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