testing-library / dom-testing-library

🐙 Simple and complete DOM testing utilities that encourage good testing practices.
https://testing-library.com/dom
MIT License
3.26k stars 466 forks source link

Overriding testIdAttribute don't work in 8.19.0 #1177

Closed jarlef closed 1 year ago

jarlef commented 1 year ago

Relevant code or config:

import { configure } from '@testing-library/dom';

configure({
  testIdAttribute: 'data-eid',
});

What you did:

What happened:

The testing framework uses the default data-testid attribute instead of the override

TestingLibraryElementError: Unable to find an element by: [data-testid="my-test-id"]

Reproduction:

https://codesandbox.io/s/jovial-lucy-6j2l5h?file=/src/App.test.tsx

Problem description:

Suggested solution:

timdeschryver commented 1 year ago

Could you please include a reproduction? It's hard to help without it.

jarlef commented 1 year ago

I have attached a link to a repro sandbox

MatanBobi commented 1 year ago

@jarlef, your example is using React but you're importing configure from @testing-library/dom. In fact, you don't need @testing-library/dom in your dependencies as @testing-library/react installs it as a dependency. I changed the import to @testing-library/react and the configure works. I'm closing this one, if it still reproduces, feel free to comment and re-open :)