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.

Regression in getByTestId when using custom testIdAttribute v7.13.0

See original GitHub issue
  • @testing-library/dom version: 7.14.0 (issue appears in all versions after 7.13.0)

  • Testing Framework and version:

    Jest 0.26.1

  • DOM Environment:

    jsdom-environment-jsdom 0.26.1

Relevant code or config:

// setup
import * as Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import 'jest-enzyme';
import 'jest-extended';
import { configure } from '@testing-library/dom';
import I18n from 'utils/i18n';

Enzyme.configure({ adapter: new Adapter() });

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

I18n.locale = 'en';

What you did:

We use data-test as our test attribute for items we can’t reach by accessible handlers. After upgrading this stopped working.

What happened:

In the error output for missing nodes when we use getByTestId we see the DOM tree we expected, but testing-library fails because it can’t find an element with the same attribute value for data-testid.

Reproduction:

https://github.com/geoffharcourt/dom-testing-library-template

Problem description:

Suggested solution:

Not sure yet!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
geoffharcourtcommented, Jun 18, 2020

OK, we figured out why this is still not working. We had two versions of the package installed, and @testing-library/react was calling the old one that didn’t have the fix #651. We’re good now, thanks for your assistance investigating and for the suggestion, @smeijer!

h/t @devinrm

1reaction
smeijercommented, Jun 14, 2020

By looking at the releases, the only thing changed in relation to the testid in 7.14 are these lines:

https://github.com/testing-library/dom-testing-library/blob/d5e17bd63c5c339d4ae29e0090f449b2c8364755/src/suggestions.js#L123:L126

To verify, they can be easily commented out. To fix, the testIdAttribute config option should be used there instead of data-testid.

I’m not sure though if/how a suggestion is able to stop queries from working.

If this is the cause, some tests should be added to cover this scenario.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuration Options | Testing Library
The library can be configured via the configure function, which accepts: a plain JS object; this will be merged into the existing configuration....
Read more >
Custom testIdAttribute ignored · Issue #874 · testing-library ...
Use configure({ testIdAttribute }) in any environment and see that it's broken now. Problem description: Hundreds and hundreds of tests break.
Read more >
Unable to find the element with data-testid - Stack Overflow
Please use the queryByTestId instead getByTestId for the case. ... It needs to be on a react native element not your custom one...
Read more >
dom-testing-library - npm
The dom-testing-library is a very light-weight solution for testing DOM nodes (whether simulated with JSDOM as provided by default with jest or ...
Read more >
Outsource that data-testid! - Hooked.io
In React Testing Library, the recommended way, after the other queries don't work for your use-case, is to add a data-testid attribute on ......
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