question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom testIdAttribute ignored

See original GitHub issue
  • @testing-library/dom version: 7.29.4
  • Testing Framework and version: Jest
  • DOM Environment:

Relevant code or config:

configure({ testIdAttribute: 'foobar' })

What you did:

Happily seeing getByTestId work, then I bumped to this version of dom-testing-library, and it stopped working.

What happened:

It’s clearly ignoring the config and searching for the default data-testid: TestingLibraryElementError: Unable to find an element by: [data-testid="bar"...

Reproduction:

Use configure({ testIdAttribute }) in any environment and see that it’s broken now.

Problem description:

Hundreds and hundreds of tests break.

Suggested solution:

It’s unfortunately hard to figure out where this broke because we get our dom-testing-library via @testing-library/react, which carets it, meaning it jumps from 7.27.1 -> 7.29.4. Somewhere in the commits in dom-testing-library between those two version numbers is the regression.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:19 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
eps1loncommented, Jan 13, 2021

Maybe we can implicitly state that there’s no need to install @testing-library/dom since everything is already exported from @testing-library/react, Wdyt?

You mean “explicitly”? If not then I don’t think that “implicit documentation” works.

It would still be nice to confirm if this is indeed the problem.

1reaction
czabajcommented, Jul 14, 2021

Happened to me today again. For further readers, if you are using Yarn, simply check that you have only one version of @testing-library/dom with

yarn why @testing-library/dom

If it discovers more than one version, upgrade all dependants and when it’s not possible, try Yarn resolutions

"resolutions": {
    "@testing-library/dom": "preferred version"
},
Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration Options | Testing Library
import serialize from 'my-custom-dom-serializer' configure({ testIdAttribute: 'data-my-test-id', getElementError: (message, container) => {
Read more >
Developers - Custom testIdAttribute ignored - - Bountysource
It's clearly ignoring the config and searching for the default data-testid : TestingLibraryElementError: Unable to find an element by: [data- ...
Read more >
Unable to find the element with data-testid - Stack Overflow
I am following the docs for react-testing-library to find if the element with data-testid attribute is rendered or not. The react-testing- ...
Read more >
What is the data-testid attribute in testing? - Educative.io
data-testid is an attribute used to identify a DOM node for testing purposes. It should be used as a handler to the test...
Read more >
Some components ignore html data attributes
However, setting a data-testid attribute (or really any data- attribute) on a Kendo component does not always result in the attribute ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found