question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ph-fritschecommented, May 10, 2021

Your reproduction works fine in codesandbox: https://codesandbox.io/s/modest-sunset-gh0of?file=/src/App.tsx

0reactions
prescottbreedencommented, May 10, 2021

It seems with the scaled down repo those indeed also hang, and I see the loop now, my thanks for your time.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found