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:
- Created 3 years ago
- Comments:8 (8 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
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 ofdata-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.