I am trying to write e2e tests for one of my UI pages which depend on NGRX state. Not sure how to set the NGRX state before starting the test. Could you please help me with this?
Asked
Active
Viewed 1,533 times
1 Answers
1
Have you read this article? https://www.cypress.io/blog/2018/11/14/testing-redux-store/
It details how to set up your tests to access / read state.
I would recommend following the steps there. For setting up the state of your store, you have two options:
- Manually in the code dispatch the correct actions that will get your state into the position you need for the test. This could be done programatically, or via cypress itself by firing off click/select/type events.
- Using NgRx 8, you can mock the store and mock selectors.
In a unit testing scenario I would argue using #1's programatic approach is a poor choice, but given this is an e2e test, both options are viable IMO.

xandermonkey
- 4,054
- 2
- 31
- 53