should getByText return a title?
See original GitHub issue@testing-library/dom
version: latest master- Testing Framework and version: node, jest 12.x, 26.x
- DOM Environment:
Relevant code or config:
test('foo', () => {
renderIntoDocument(` <svg>
<title data-testid="svg">Close</title>
<g><path /></g>
</svg>`)
screen.debug(screen.getByText('Close'))
})
What you did:
called screen.getByText
What happened:
I got back the title… but shouldn’t getByText be accessible to everyone? If it’s hidden, it won’t be accessible to sighted users.
Reproduction:
Problem description:
Suggested solution:
have getByText ignore <title> elements.
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (10 by maintainers)
Top Results From Across the Web
About Queries | Testing Library
findBy... : Returns a Promise which resolves when an element is found which matches the given query. The promise is rejected if no...
Read more >How to expect a getByText to be false in react testing library?
But I would like to test as well that the modal does not exist before the triger event. So I decided to expect...
Read more >How to use the react-testing-library.fireEvent.click function in ...
test(`User should be able to add a new checkbox item. ... toThrow(); // Validate TOC not open expect(() => getByText('Title')).toThrow(); // Open TOC...
Read more >React Testing Library Examples
queryByText and getByText to select a node and assert its presence ... Unchecking will return to the original document title fireEvent.click(checkbox); ...
Read more >React-Testing-Library — Pro tips. Extends expect of ... - Jero
In this post, we will see a set of tips and recommendations about the use of the React ... return ( <form> <label...
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
This change of mind brought to you by: https://github.com/testing-library/cypress-testing-library/issues/134
In fact, the original reason for
ignore
was becausegetByText
was getting me translation text that was served up in thescript
tag for my app when using cypress 😅 Seems it would make sense to add some other tags now that I think about it.Anyone wanna do this?
I actually am using it to check for the presence of svg so I do think we should keep it. I’m just saying it should return the element it’s a title for rather than the title element itself. Just like how get by label text will return the input element rather than the label.