testing-library / testing-library/dom-testing-library
getByTestId not working when upgrading @testing-library/dom from version 9.3.1 to 9.3.2 or above
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 3.3k
- Forks
- 474
- PR merge metrics
- No merged PRs in 30d
Description
Possibly also the reason for this issue:
findByRole doesn't find the role
@testing-library/dom version: 9.3.2
- Testing Framework and version:
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.1.0",
"@types/jest": "^29.5.8",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
Relevant code or config:
test('FacetSize callback', async () => {
render(<div data-test-id="123">Test</div>);
const testTestId = screen.getByTestId('123');
await waitFor(() => expect(testTestId).toBeInTheDocument());
});
What you did:
Ran test according to above
What happened:
Getting this error:
TestingLibraryElementError: Unable to find an element by: [data-testid="123"]
Ignored nodes: comments, script, style
<body>
<div>
<div
data-test-id="123"
>
Test
</div>
</div>
</body>
Problem description:
Test fails when running with @testing-library/dom version higher than 9.3.1
Exact same code works with version 9.3.1 and below.
Suggested solution:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the supplied test with @testing-library/dom 9.3.1 and 9.3.2, checking the data-test-id markup against the getByTestId entry point. Trace the version change affecting this lookup and add a regression test if the behavior is confirmed; done means the test reliably finds the element on supported versions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100