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 cannot test form actions #54757
Comments
I think you may need to install |
Thanks for the comment. Thanks to you I was able to make the test work as intended. It worked with experimental react and react-dom, but even with canary, the test worked as intended in my environment. Since canary uses code closer to the next version, it may be better to use canary if it works here. |
I have the same error for a form action on a component when testing in JEST.
Operating System:
|
Same isse here, running from Ubuntu 22.04.
Node and npm versions:
Relevant packages:
|
I am facing the same issues.
|
Similar here as well, but I had initially tried with Vitest which didn't throw the error seen in the comment: #54757 (comment) Moving over to Jest it does throw the "action is an invalid prop" error. So sight differences depending on the test framework you wish to use, but neither actually work. |
I'm encountering this issue using Next.js out of the box |
I had some discussions regarding other problems with the Testing library and NextJS some weeks ago in their repo. They suggested that there's a mismatched version between NextJS envs and test envs. Meanwhile Next is using React Canary, probably the test environment is still in React 18.2. That could explain as well this possible issue. React 19 should solve this issue (if I am not wrong). |
I experienced a variation of this issue here: #64783 The fundamental problem is that next is using an internal version of react that testing libraries (and any other normal node process) won't have access to. It isn't clear at all when the package version of react/react-dom will be resolved, and when the internal one will. You can configure a resolve alias to fix some of your testing scenarios, but it is just a bad design IMO. |
Verify canary release
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP PREEMPT_DYNAMIC Thu Jul 27 20:01:18 UTC 2023 Binaries: Node: 18.16.0 npm: 9.5.1 Yarn: 1.22.19 pnpm: N/A Relevant Packages: next: 13.4.10 eslint-config-next: 13.4.10 react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.6 Next.js Config: output: standalone
Which area(s) of Next.js are affected? (leave empty if unsure)
Jest (next/jest)
Link to the code that reproduces this issue or a replay of the bug
https://github.com/Dinika/nextjs-serveractions-jest
To Reproduce
Describe the Bug
While I am able to test component that call server actions (by using the
action
prop onform
element), I am not able to test that a given server action was called or that the form was submitted. I get the following error:Expected Behavior
It should be possible to test that the form was submitted.
Which browser are you using? (if relevant)
firefox
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: