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

Testing an effect that uses withLatestFrom #1668

Closed
Fallenstedt opened this issue Mar 30, 2019 · 2 comments
Closed

Testing an effect that uses withLatestFrom #1668

Fallenstedt opened this issue Mar 30, 2019 · 2 comments

Comments

@Fallenstedt
Copy link

Fallenstedt commented Mar 30, 2019

Minimal reproduction of the bug/regression with instructions:

This issue is regarding tests. You can clone this simple example here: https://github.com/Fallenstedt/users-ngrx

  1. npm install
  2. ng test screens

Expected behavior:

The effect uses withLatestFrom to pipe off the store and obtain data in the store.

Removing or adding withLatestFrom in the effect will make the test pass or fail respectively.

The error I see when I have an effect using withLatestFrom is

  {
    "message": "An error was thrown in afterAll\nUncaught TypeError: Cannot read property 'loaded' of undefined thrown",
    "str": "An error was thrown in afterAll\nUncaught TypeError: Cannot read property 'loaded' of undefined thrown"
  }

I would expect tests to pass when my effect uses withLatestFrom

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s):

"@angular/core": "^7.0.0",
"@ngrx/effects": "7.4.0",
"@ngrx/entity": "^7.4.0",
"@ngrx/router-store": "7.4.0",
"@ngrx/store": "7.4.0",
 node:  v9.8.0

Other information:

This issue references #414. Other people still have problems with this when using ngrx v7

I would be willing to submit a PR to fix this issue

[X] Yes!!!!!!!!!!!!!!!!!! (Assistance is provided if you need help submitting a pull request)

@King-i
Copy link
Contributor

King-i commented Mar 30, 2019

I dont think this is an issue with NGRX or your test setup,
In the example you have provided https://github.com/Fallenstedt/users-ngrx
You have defined your state as:
{ user: UsersState }
but you are loading in your feature state as export const USERS_FEATURE_KEY = 'users';

changing either your feature state to user or your state interface to users will solve your issue?
EDIT:
ive just tested it and its correct, your state/definitions are incoherent, follow the tip above to rectify
image

@Fallenstedt
Copy link
Author

Fallenstedt commented Mar 30, 2019

@King-i I cannot thank you enough. Last night I was so confused as to why I could not get my effects to to run properly. A single missing character led to so much confusion. I need to use my USERS_FEATURE_KEY liberally.

This is a classic "D'oh!" moment. I applied changes, and my tests work properly now.

Thank you for your help.

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