act() warnings when using React Hook Form
See original GitHub issue🐛 Bug Report
When a form that’s using form.register() from React Hook Form is conditionally rendered within a test, act() warnings are printed in the console.
A workaround seems to be to:
import { render } from '@testing-library/react'
const { page } = getPage({route: '/'})
render(page)
In the reproduction repo both variants (render from npt, render from tl) are used.
To Reproduce
- Create a page with a form. Set a
refon an input in the form usingform.register(). - Mount and unmount the form within the page with a toggle switch In a test:
- Render the page with
render()fromgetPage() - act on the toggle switch to mount the form
- console logs an
act()warning
Expected behavior
No warnings
Link to repl or repo
https://github.com/osadi/npt-react-hook-form
Should work with npm i && npm run test
Run npx envinfo --preset jest
npx: installed 1 in 0.964s
System:
OS: Linux 5.4 Manjaro Linux
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Binaries:
Node: 14.15.0 - ~/.nvm/versions/node/v14.15.0/bin/node
Yarn: 1.22.10 - /usr/bin/yarn
npm: 6.14.8 - ~/.nvm/versions/node/v14.15.0/bin/npm
npmPackages:
jest: ^26.6.3 => 26.6.3
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
act warnings with testing-library · Discussion #3108 - GitHub
Hi, I read the following doc about testing using react-hook-form with testing-library: ... it('renders without warnings', () => { render( <MyTestForm ...
Read more >Advanced Usage - React Hook Form
React Hook Form's FormProvider is built upon React's Context API. It solves the problem where data is passed through the component tree without...
Read more >How to use soft validation (aka tips or warning messages) in ...
I would like to find a solution that plays well with React Hook Form V7. The Problem: React Hook Form V7 only supports...
Read more >Fix the "not wrapped in act(...)" warning when testing Custom ...
In this lesson you'll learn how you can use act with @testing-library/react-hooks to avoid potential bugs in your custom React hooks. This is...
Read more >Using React Hook Form in component tests | by Adam J. Arling
This article illustrates our team's approach to organizing and testing nested form components, using React Hook Form's <FormProvider /> and useFormContext() ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It might be as simple as wrapping our
hydratecall into react’sacttest utility, but I would like to do it on a reproducer without external dependency so we have a stable test for it.Ah, I though you are receiving
actwarning after just afterrendering– not after performing client interactions. Those are out of scope of the library and its a known issue withreact-hook-form, e.g. see https://github.com/testing-library/user-event/issues/457 for example.