question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ngxs/store @select decorator compatibility

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
getsafcommented, Jun 19, 2018

Glad it worked out! I’m going to close this issue.

1reaction
getsafcommented, Jun 18, 2018

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 or neverMock the thing you pass into the dontMock/neverMock method must === the module/provider/component/etc from the component’s module. In this case, when using NgxsModule.forRoot() in the component’s module, the forRoot method yields a singleton object (an NgModuleWithProviders) that we must gain access to so we have a thing that Shallow can === compare to skip mocking.

My solution was simply to export the rooted NgxsModule and pass that into the dontMock in the spec. You may use neverMock 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found