userEvent.click on component with React Hook causes Jest to hang indefinitely (when run locally)
See original GitHub issue@testing-library/user-event
version: 12.1.10
- Testing Framework and version: Jest: (CRA - 26.6.3)
- DOM Environment: CRA(jsdom - 26.6.2)
Relevant code or config: see repo for context – code that causes the bug is the following:
const button = screen.getByRole('button', { name: /submit/i });
userEvent.click(button);
What you did: calling userEvent.click on a button that triggers a react hook
What happened: Jest hangs indefinitely without timeout, no error messages
Reproduction repository: https://github.com/prescottbreeden/hanging-test-repro
Problem description:
I have a validation library that uses a react hook, and interestingly, I can use fireEvent
and any other userEvent
methods on the button that triggers the hook to run without a problem, but when I used userEvent.click
specifically, Jest hangs infinitely.
Suggested solution: unsure
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Error thrown when using react hooks · Issue #128 - GitHub
Description Given a react component using hooks When a you attempt to use a user ... Wrapping userEvent.click in act similarly causes the...
Read more >userEvent in React Testing Library Doesn't Cause onClick To ...
I had the same problem, fireEvent works but the recommended userEvent doesn't trigger click handler. Turned out that userEvent is async.
Read more >Continuous integration for React applications using Jest and ...
The best way to do that is to clone the app and run it locally. ... https://github.com/CIRCLECI-GWP/react-jest-enzyme.git npm install npm ...
Read more >An in-depth beginner's guide to testing React applications in ...
Find out what to test and which testing framework to use. Learn a clear approach by writing tests for an extensive example app...
Read more >useEffect – How to test React Effect Hooks - cultivate
Learn how to test a useEffect hook, how to handle infinite rendering loops, how to deal with a not wrapped in act(..) warning,...
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
Your reproduction works fine in codesandbox: https://codesandbox.io/s/modest-sunset-gh0of?file=/src/App.tsx
It seems with the scaled down repo those indeed also hang, and I see the loop now, my thanks for your time.