Error thrown when using react hooks
See original GitHub issueDescription
Given a react component using hooks When a you attempt to use a user event e.g. type Then you receive the error below
Warning: An update to %s inside a test was not wrapped in act(...).
Reason
As far as I understand this is because we are using the fireEvent
from @testing-library/dom
directly and not from @testing-library/react
which means that it is not being in act
.
Solution
A possible solution would be to allow for the user to provide a fireEvent
implementation or allow for this to be configured in test setup
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:40 (20 by maintainers)
Top Results From Across the Web
Error Handling in React Hooks - Medium
Error Handling in Hooks is quite Simple. In this article, we are going to demonstrate how to handle errors in React Hooks.
Read more >Handle Error While Testing Your React Hooks
Handle errors when a hook is called The reason is that it can throw an exception that cannot be handled. It is impossible...
Read more >Why can React hooks be used conditionally with throw errors?
By throwing an error you are bailing out of the rest of the render, so whether or not a React hook is callable...
Read more >Throwing Error from hook not caught in error boundary #14981
This may be more of a question than an issue but is it possible to throw errors in a hook and have them...
Read more >Invalid Hook Call Warning - React
You are probably here because you got the following error message: Hooks can only be called inside the body of a function component....
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 FreeTop 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
Top GitHub Comments
This issue is still happening. Why is this lib still using the
fireEvent
from the@testing-library/dom
? Any idea if that’s going to be changed/fixed?If I strip it right back, all is fine:
BasicForm.js:
BasicForm.test.js:
The problem is only present when I use
handleSubmit
from react-hook-form:BasicForm.js:
npm run test BasicForm: