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

initialState on StoreModule.forFeature ignored #206

Closed
lucastheisen opened this issue Jul 28, 2017 · 5 comments
Closed

initialState on StoreModule.forFeature ignored #206

lucastheisen opened this issue Jul 28, 2017 · 5 comments

Comments

@lucastheisen
Copy link

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request

What is the current behavior?

In my unit tests, I have a simple setup function:

        function setup(...airports: Array<{airport: Airport, style?: fromViewerData.GeoJsonStyle}>) {
            const [store, airport] = initialState(...airports);
            console.log("REMOVE ME: store: %s", JSON.stringify(store, null, 2));
            console.log("REMOVE ME: airport: %s", JSON.stringify(airport, null, 2));
            TestBed.configureTestingModule({
                imports: [
                    StoreModule.forRoot(fromEventAnalyzer.reducers(), {initialState: store}),
                    EffectsModule.forRoot([]),
                    StoreModule.forFeature(AirportPlugin.ID, reducer, {initialState: airport}),
                    EffectsModule.forFeature([AirportEffects]),
                    ToasterModule,
                ],
                providers: [
                    Actions,
                    { provide: StyleGenerator, useValue: StaticStyleGenerator.INSTANCE },
                    { provide: AirportService, useClass: MockAirportService },
                    { provide: LoggerService, useClass: ConsoleLoggerService },
                ],
            });
            TestBed.get(Store).select(fromEventAnalyzer.getState)
                .subscribe((state: fromEventAnalyzer.EventAnalyzerState) => {
                    console.log("REMOVE ME: state: %s", JSON.stringify(state, null, 2));
                });

            return {
                actions: TestBed.get(Actions) as Actions,
                logger: TestBed.get(LoggerService) as LoggerService,
                service: TestBed.get(AirportService) as AirportService,
                store: TestBed.get(Store) as Store<fromEventAnalyzer.EventAnalyzerState>,
            };
        }

This allows me to hydrate the store with a known initial state before each test. Using the console.log statements, I verified that the incoming state correct, however, the store only initializes the store half, and leaves the airport half uninitialized (falls through to the default value defined in the reducer). Perhaps I am doing something wrong by including both a forRoot and a forFeature in the same imports, but not sure on that...

Expected behavior:

The Store should be initialized with both sets of initialState.

Minimal reproduction of the problem with instructions:

I attempted to create a reproduction by creating another test in this project, but alas, I am unable to build:

PS C:\Users\ltheisen\git\ngrx-platform> npm run build

> @ngrx/platform@4.0.0 build C:\Users\ltheisen\git\ngrx-platform
> ts-node ./build/index.ts

√ Removing "./dist" Folder
√ Compiling packages with NGC
√ Bundling FESMs
√ Down-leveling FESMs to ES5
√ Creating UMD Bundles
√ Renaming package entry files
√ Cleaning TypeScript files
√ Removing remaining sourcemap files
× Copying type definition files
{ Error: ENOENT: no such file or directory, chmod 'C:\Users\ltheisen\git\ngrx-platform\dist\effects\src\actions.d.ts'
  errno: -4058,
  code: 'ENOENT',
  syscall: 'chmod',
  path: 'C:\\Users\\ltheisen\\git\\ngrx-platform\\dist\\effects\\src\\actions.d.ts' }
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ngrx/platform@4.0.0 build: `ts-node ./build/index.ts`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ngrx/platform@4.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ltheisen\AppData\Roaming\npm-cache\_logs\2017-07-27T21_45_51_702Z-debug.log

Perhaps you don't support windows for builds?

Version of affected browser(s),operating system(s), npm, node and ngrx:

Windows: Microsoft Windows [Version 10.0.14393]
node: v8.2.1
npm: 5.0.3
ngrx/store: 4.0.0
ngrx/effects: 4.0.1

Other information:

💗 ngrx? Please consider supporting our collective: 👉 donate

@lucastheisen
Copy link
Author

For know, i can work around this using:

...
            const [store, airport] = initialState(...airports);
            console.log(`REMOVE ME: store: ${JSON.stringify(store, null, 2)}`);
            console.log(`REMOVE ME: airport: ${JSON.stringify(airport, null, 2)}`);
            // Waiting on https://github.com/ngrx/platform/issues/206
            let hack206 = Object.assign({}, store, {[AirportPlugin.ID]: airport});
            TestBed.configureTestingModule({
                imports: [
                    StoreModule.forRoot(fromEventAnalyzer.reducers(), {initialState: hack206}),
...

@brandonroberts
Copy link
Member

Can you provide a small reproduction of this issue in a repo?

@brandonroberts
Copy link
Member

The build issues should be fixed. You don't need to do a build to run the tests though

@lucastheisen
Copy link
Author

I can confirm the build issues were fixed. Let me see if i can reproduce my problem with a spec...

@lucastheisen
Copy link
Author

Okay, @brandonroberts , i have submitted a pull request with an integration test that demonstrates this issue. Not sure it fits with the flavor of the project, so you may not want to merge it, but it was the simplest way I could come up with... Thanks for looking into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants