dom-testing-library: getByTestId not working when upgrading @testing-library/dom from version 9.3.1 to 9.3.2 or above

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:

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 4
  • Comments: 16 (8 by maintainers)

Most upvoted comments

@janeklb nope, but once we’ll release the new version of RTL we can push the ecosystem to do the same 😃

This is probably related to the multiple versions of @testing-library/dom. We’re working on moving DTL to peer in RTL and will probably recommend doing that for other libraries in the organization too, this should resolve it.