diff --git a/modules/store/spec/modules.spec.ts b/modules/store/spec/modules.spec.ts index 5a6690c691..7bcf7ff883 100644 --- a/modules/store/spec/modules.spec.ts +++ b/modules/store/spec/modules.spec.ts @@ -119,6 +119,40 @@ 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) => { + console.log('ACTION', state); + 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 a simple no-op meta reducer', + testWithMetaReducers([noopMetaReducer]) + ); + }); + describe(`: Nested`, () => { @NgModule({ imports: [StoreModule.forFeature('a', featureAReducer)], diff --git a/modules/store/src/utils.ts b/modules/store/src/utils.ts index a8a30c7642..7a20f50ce5 100644 --- a/modules/store/src/utils.ts +++ b/modules/store/src/utils.ts @@ -72,7 +72,7 @@ export function compose( b: (i: A) => B ): (i: A) => F; export function compose(...functions: any[]) { - return function(arg: any) { + return function(...arg: any[]) { if (functions.length === 0) { return arg; } @@ -80,7 +80,7 @@ export function compose(...functions: any[]) { const last = functions[functions.length - 1]; const rest = functions.slice(0, -1); - return rest.reduceRight((composed, fn) => fn(composed), last(arg)); + return rest.reduceRight((composed, fn) => fn(composed), last(...arg)); }; }