-
Notifications
You must be signed in to change notification settings - Fork 458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
should getByText return a title? #593
Comments
There are a lot of situations where you could get an element back that's hidden: // <div style="display:none;">Hi</div>
screen.getByText(/hi/i) // <div.... I'm not sure whether we can deliver on the promise that we'll never return you something that's not hidden (though |
true, but in this case it's not just a styling thing. afaik the browser will never show the text of a <title> element. title is semantically different than text no? anyway only reason this came up was because in the suggestions feature I tried to add a test for it (because it's actually listed in the examples when i went thru 'which query should i use" and i realized that getByTitle will ALWAYS be recommending getByText when you use <title>... which seemed kinda strange to me anyway food for thought. :) |
What about dom-testing-library/src/queries/text.js Line 17 in 4fb0093
Should be pretty easy actually... |
This change of mind brought to you by: testing-library/cypress-testing-library#134 In fact, the original reason for Anyone wanna do this? |
Ah I see what you mean @kentcdodds this is easy to fix. What other tags do you think should be ignored by default? I can fix it as suggestions would need the same change. |
I don't know for sure. Would take a little bit of research. |
alright. i can try and see what i find and report back. somewhat related, what do you think of <svg onclick="..."><title>foo</title><path /></svg> that it returns the especially when i want to do |
Honestly, I can't remember why we added that one and I don't use it myself so my understanding of the implications of removing it is limited. If you could do some archeology on that too figure out what use cases it's intended for them we can make a more informed decision. |
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. |
That makes sense to me. Let's just make sure we understand the reason it was created so we don't miss something. Also, this would be a breaking change. Perhaps we could make a new query |
I am chiming in here as someone who has a similar problem. I am testing for the display of an svg using |
How are you guys able to use |
@testing-library/dom
version: latest masterRelevant code or config:
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.
The text was updated successfully, but these errors were encountered: