Tests data-testid is being ignored / not being passed down
See original GitHub issueVersion 5.1.4
Steps to reproduce
// App.tsx
export default () => (
<Typeahead
data-testid='search-bar-input'
placeholder="Test"
filterBy={() => true}
autoFocus={true}
options={[]}
/>
)
Then import that file into a test using react-testing-library
// App.test.tsx
import { render } from '@testing-library/react';
import App from './App';
it('should be focused', async () => {
const { getByTestId, container } = render(<App />);
// console.log(container.innerHTML)
const input = getByTestId('search-bar-input')
expect(input).toHaveFocus()
});
Expected Behavior
It should pass the test
Actual Behavior
It cannot find search-bar-input
If we do a console.log(container.innerHTML)
the result has no ‘search-bar-input’ at all
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
The data-testid won't work if div isn't wrapped #377 - GitHub
I've been a real lover of react-testing-library these days. ... or it passes the test id down to the child native component that...
Read more >Unable to find the element with data-testid - Stack Overflow
The react-testing-library is not able to find the element even though it exists. TEST test('Renders step based on the active step', () =>...
Read more >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 >Some components ignore html data attributes
Some components ignore html data attributes. In our unit tests, we sometimes want to be able to use the ByTestId methods of the...
Read more >Testing-library: avoid these mistakes in async tests
Sometimes, tests start to unexpectedly fail even if no changes were made to the business logic. It may happen after e.g. you updated...
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 FreeTop 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
Top GitHub Comments
Temporally I have added the attribute ‘inputProps’ with a forced typing
Passing inputProps without a type works fine and perfectly for react-testing-library! (or any other testing library like Enzyme)