Cannot access disabled button
-
@testing-library/domversion: 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:
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.
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:
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:
- Manually install
@testing-library/dom@^8 - 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 😢 .