Replies: 1 comment 2 replies
-
Hi @wcastand !! What’s happening is that handleSubmit in react-hook-form can be async, and so can your navigation (router state updates aren’t synchronous). In a test, if you immediately assert after fireEvent.submit or userEvent.click, the transition hasn’t completed yet. A couple of ways to fix it:
If you’re using next/navigation, the push happens in a microtask → so waitFor is required. act() won’t help unless you wrap the async. So the pattern is: trigger submit → await waitFor until router has updated. That should make your toHavePathname assertion reliable. |
Beta Was this translation helpful? Give feedback.
2 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.
Uh oh!
There was an error while loading. Please reload this page.
-
https://github.com/wcastand/react-hook-form-test
when i run the test, the test fails because it has no time to go to next screen in the onSubmit.
In my real app, i get a mutation/fetch too and same result, the toHavePathname doesn't work but first transition works.
not sure how i'm suppose to make it work. any help appreciated.
i tried act or to waitFor but doesn't do anything
Beta Was this translation helpful? Give feedback.
All reactions