Platform: Testing an effect that uses withLatestFrom

Created on 30 Mar 2019  路  2Comments  路  Source: ngrx/platform

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)

Most helpful comment

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

All 2 comments

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

@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.

Was this page helpful?
0 / 5 - 0 ratings