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

Cannot access disabled button #1217

Open
pschyma opened this issue Feb 18, 2023 · 2 comments
Open

Cannot access disabled button #1217

pschyma opened this issue Feb 18, 2023 · 2 comments

Comments

@pschyma
Copy link

pschyma commented Feb 18, 2023

  • @testing-library/dom version: 9.0.0
  • Testing Framework and version: vitest 0.28.5
  • DOM Environment: jsdom 21.1.0

Relevant code or config:

const upload = screen.getByRole('button', { name: /upload/i });

What you did:

Updated from version 8.4.0 to 9.0.0 and rerun test.

What happened:

Error: Test timed out in 5000ms.
If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout".
    at Timeout.<anonymous> (file:///.../frontend/node_modules/@vitest/runner/dist/index.js:44:16)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)

TestingLibraryElementError: Unable to find an accessible element with the role "button" and name `/upload/i`

There are no accessible roles. But there might be some inaccessible roles. If you wish to access them, then set the `hidden` option to `true`. Learn more about this here: https://testing-library.com/docs/dom-testing-library/api-queries#byrole

I tried the hidden: true option, but there was no change.

Reproduction:

Problem description:

Suggested solution:

@MatanBobi
Copy link
Member

MatanBobi commented Feb 18, 2023

Can you please share a minimal reproduction? I tried reproducing this one with the latest RTL version which is using @testing-library/[email protected] and this issue didn't reproduce.

@william-will-angi
Copy link

william-will-angi commented Mar 9, 2023

Posting here because I also ran into these issues after regenerating my app's package-lock.json.

I had installed versions:

@testing-library/react: 12.1.5
@testing-library/user-event: 14.4.3

After regenerating the package-lock.json, two different versions of @testing-library/dom were downloaded:

Screen Shot 2023-03-08 at 6 22 37 PM

With multiple versions of @testing-library/dom, I experienced the same issues mentioned in this issue.

I was able to resolve the issues by doing either of the following:

  1. Manually install @testing-library/dom@^8
  2. Add the following property to my package.json:
  "overrides": {
    "@testing-library/react": {
      "@testing-library/dom": "^9"
    }
  }

I think the best solution would be to patch @testing-library/react v12/13 to allow for @testing-library/dom v8 & v9, but I don't think it's maintained anymore since it's two major releases behind 😢 .

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

3 participants