Migrate mocked useNavigate hook that uses jest.requireActual #940
Unanswered
florianwittmann
asked this question in
Q&A
Replies: 2 comments 1 reply
-
|
We won't support |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Here is the solution to mock useNavigate hook for vitest and jest. IMPORTANT:- Use react-router instead of react-router-dom Component File Mock --> test.jsx file
Here I'm rendering App if you want to start your test from a specific page where your button is mount you can do that as well by memory-router. Get more details here unit/testing/react |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Regarding this thread (testing-library/react-hooks-testing-library#588), I mocked the useNavigate function the following way in jest:
This does not seem to work now in vitest yet - Maybe there is an alternative way to mock the useNavigate hook until requireActual is also working in vitest? I would love to be able to drop jest in favor of vitest already.
Beta Was this translation helpful? Give feedback.
All reactions