Replies: 4 comments 5 replies
-
have a look at this section: https://react-hook-form.com/advanced-usage#TestingForm also it's good to remember everything in hook form is async around validation. |
Beta Was this translation helpful? Give feedback.
-
I too am having this problem, I can't reproduce on
For me, this was working fine before various package upgrades. I'm now going to try and isolate exactly what caused this problem. Any help much appreciated and loving the library 🙌 |
Beta Was this translation helpful? Give feedback.
-
https://codesandbox.io/s/hardcore-tereshkova-wuurh - WIP Codesandbox too |
Beta Was this translation helpful? Give feedback.
-
I found that explicitly unmounting the tested component resolves the issue, but I don't know why: it('renders without warnings', () => {
const { unmount } = render(<MyTestForm />);
expect(true).toBeTruthy();
unmount();
}); Additionally, I found the warning would go away as long as the test contains awaiting any user interaction. For example: it('renders without warnings', () => {
const user = userEvent.setup();
render(<MyTestForm />);
await user.click(screen.getByRole('button')); // assuming your screen has a button
expect(true).toBeTruthy();
}); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I read the following doc about testing using react-hook-form with testing-library:
https://react-hook-form.com/faqs#TestingReactHookForm
I have updated setup.js with
import "@testing-library/jest-dom";
and it is importing correctly but I am getting warnings about act when I run my test.My test is really simple:
And the component looks like this:
The test passes but I get this error on running:
Any idea what could be causing this? I'm assuming react-hook-form is updating on initial render or something? Or perhaps calling setState when the test framework unmounts it?
If I remove the ref prop (disabling react-hook-form) then I get no warnings and the test passes.
My dep versions are:
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions