how to stub or spy react-redux useDispatch/useReducer hooks when using cypress/react #15064
Replies: 8 comments 1 reply
-
ofcourse, when using jest, you can simply do something like this:
To openly embrace @cypress/react - i think we're really going to need to be able to do similar. |
Beta Was this translation helpful? Give feedback.
-
Any updates? |
Beta Was this translation helpful? Give feedback.
-
I have an idea for a solution for this. Ill let you know if I'm able to make any progress |
Beta Was this translation helpful? Give feedback.
-
Any update @jordanpowell88? |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, no. I have not had a chance to work on examples for these as I've been pretty heads down on some other initiatives. I hate to be the bearer of bad news but wanted to at least get you a response. |
Beta Was this translation helpful? Give feedback.
-
My team is also working on migrating our Jest unit tests to Cypress component tests.. But this is a real bummer.. |
Beta Was this translation helpful? Give feedback.
-
Not sure if this helps OP, but this is the first thread that comes in the results so I'll leave an answer here in case it helps someone else. I managed to indirectly spy on
and then in your specs: In my use case, I needed to spy whether a component calls |
Beta Was this translation helpful? Give feedback.
-
I attempted to stub the Redux dispatch function in various ways, but none were successful. Instead, I used Redux middleware to mock functions, which allowed me to achieve the intended result.
The |
Beta Was this translation helpful? Give feedback.
-
Im trying to pitch that our dev team purely use cypress/react instead of jest/jsdom for component unit testing. The one big roadblock standing in the way of this right now tho, is being able to match jest's excellent import mocking functionality.
could someone please help me understand how to stub (or even spy on) the useReducer hook imported from react-redux? This code looks like it should work, but it just doesn't (stub never intercepts the useReducer function).
the "something" stub does indeed trigger and intercept the import, but the useSelector stub does not. :(
help
the component in question is SUPER simple too:
Beta Was this translation helpful? Give feedback.
All reactions