-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jest/Vitest unit testing: TypeError: (0 , _reactdom.useFormStatus) is not a function #63868
Comments
I get these same types of errors when my tests touch code that contains Edit: created an issue for my case of this: #64783 |
Was this ever resolved ? Got a similar error When I remove uses of |
Note Next.js doesn't use the react version in your package.json, it uses a pre-compiled canary version. Updating react (or even removing it) will only affect tests. |
Thanks. Successfully implemented the first and third option. For the third, which is what I will be using for projects I am currently working:
|
Just to set expectations, the code I posted last night mocking useFormStatus just prevents the error. The test I was originally working on when posting this issue doesn't care about useFormStatus or its parameter values. Later I did try a test where I destructured the mock to set the pending parameter to be true. I could not get this to work. Stepping through the code pending always shows undefined.
Have to move along to other priorities, but if I do find a way to make this usable in a test will post here. |
Installing canary versions of react and react-dom worked for me! And a big thank you for your note as I am always wary of creating larger unforeseen issues by correcting an issue at hand. |
I was able to mock useFormStatus only like this:
Paste it on top of your test file and it should work. |
Link to the code that reproduces this issue
https://github.com/SunDevils0/with-jest-app
To Reproduce
Current vs. Expected behavior
Current
Receive error: TypeError: useFormStatus is not a function
Expected
No error received and rest of test able to be evaluated.
Provide environment information
Which area(s) are affected? (Select all that apply)
Jest (next/jest), TypeScript (plugin, built-in types)
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
The text was updated successfully, but these errors were encountered: