Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

await user.click() as suggested by the docs doesn't work #1054

Closed
targumon opened this issue Sep 7, 2022 · 2 comments
Closed

await user.click() as suggested by the docs doesn't work #1054

targumon opened this issue Sep 7, 2022 · 2 comments

Comments

@targumon
Copy link

targumon commented Sep 7, 2022

Reproduction example

https://codesandbox.io/s/intelligent-maria-lqp7d9?file=/src/Button.test.tsx

Prerequisites

In codesandbox just switch to the 'Tests' tab.

Expected behavior

Based on the example in the docs (https://testing-library.com/docs/user-event/intro/)
I expected this will make the test pass:

await user.click(screen.getByRole('button'))

Actual behavior

The test fails.

  • In CSB the error is "The provided value is not of type 'Element'"
  • In my original project (before reducing to smallest example) the test runner is jest and it throws "Exceeded timeout of 5000 ms for a test".

In both cases solved by:

await waitFor(() => user.click(screen.getByRole('button')))

So either the docs are right and there's a bug or the docs are wrong.

User-event version

14.4.3

Environment

No response

Additional context

This is just the tip of my frustration iceberg following the upgrade to @TL/react 13 + @TL/user-event 14
See my comment here: testing-library/react-testing-library#1061 (comment)

@targumon targumon added bug Something isn't working needs assessment This needs to be looked at by a team member labels Sep 7, 2022
@ph-fritsche
Copy link
Member

In Codesandbox the document in the test is not globalThis.document.
You need to call userEvent.setup({document}) inside the test.
https://codesandbox.io/s/userevent-react-vbcvs?file=/src/testEnv.js
https://testing-library.com/docs/user-event/options/#document

For the timeout issue in jest:
If you use fake timers, see https://testing-library.com/docs/user-event/options/#advancetimers .

@ph-fritsche ph-fritsche removed bug Something isn't working needs assessment This needs to be looked at by a team member labels Sep 14, 2022
@ph-fritsche ph-fritsche closed this as not planned Won't fix, can't repro, duplicate, stale Sep 14, 2022
@targumon
Copy link
Author

The difference with CSB is because of being run in an iframe? Good to know!

And I indeed useFakeTimers - thank you for helping! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants