Ngxs/store @select decorator compatibility
See original GitHub issueI couldn’t test components using @select decorator of ngxs/store, I’m without new ideas how to test it!
if I try to provide store I’ve got this error:
SelectFactory not connected to store!
at LoginComponent.createSelect (node_modules/@ngxs/store/bundles/ng:/@ngxs/store/packages/store/src/select.ts:45:15)
at LoginComponent.get [as conf] (node_modules/@ngxs/store/bundles/ng:/@ngxs/store/packages/store/src/select.ts:73:1)
at Object.View_LoginComponent_0._co [as updateDirectives] (ng:/DynamicTestModule/LoginComponent.ngfactory.js:237:31)
at Object.debugUpdateDirectives [as updateDirectives] (../../../../../execroot/angular/packages/core/src/view/services.ts:384:19)
at checkAndUpdateView (../../../../../execroot/angular/packages/core/src/view/view.ts:359:12)
If I try to provide store and don’t mock it, I’ve got this one:
● LoginComponent Shallow Render › should log in
StaticInjectorError(DynamicTestModule)[Store -> StateStream]:
StaticInjectorError(Platform: core)[Store -> StateStream]:
NullInjectorError: No provider for StateStream!```
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Select - NGXS
You can select slices of data from the store using the @Select decorator. It has a few different ways to get your data...
Read more >Announcing NGXS 3.5 - Medium
NGXS 3.4 works perfectly with Angular 8 but now as of 3.5 we officially support this latest version of Angular. It has been...
Read more >@ngxs-labs/select-snapshot - npm package | Snyk
As you may notice we don't have to inject the Store class and invoke the selectSnapshot on it. ViewSelectSnapshot. @ViewSelectSnapshot is a decorator...
Read more >Ngxs | npm.io
ngxs /store, @ngxs/devtools-plugin, @ngxs/logger-plugin, @ngxs/router-plugin, ... To install the `@ngxs-labs/dispatch-decorator`, run the following command:.
Read more >@ngxs/store | Yarn - Package Manager
NGXS Labs ; NGXS-labs Dispatch decorator, @ngxs-labs/dispatch-decorator · latest ; NGXS-labs Select snapshot decorator, @ngxs-labs/select-snapshot · latest ; NGXS- ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Glad it worked out! I’m going to close this issue.
Cool, the StackBlitz helped me understand a lot. Here’s what I found. Looks like since they are using a
forRoot
+ decorators, things get a little weird which is why they are using static properties behind the scenes.Unfortunately, if you want to use
dontMock
orneverMock
the thing you pass into thedontMock
/neverMock
method must===
the module/provider/component/etc from the component’s module. In this case, when usingNgxsModule.forRoot()
in the component’s module, theforRoot
method yields a singleton object (anNgModuleWithProviders
) that we must gain access to so we have a thing thatShallow
can===
compare to skip mocking.My solution was simply to export the rooted
NgxsModule
and pass that into thedontMock
in the spec. You may useneverMock
in the same manner if you want to just do it once for all your specs.This was an interesting problem to solve. I may try to think of a way to make this more intuitive or put something in the docs for the next person to run across something like this.
Here’s my fork of your StackBlitz: https://stackblitz.com/edit/angular-shallow-render-select-specs?file=src/app/app.component.spec.ts