-
Notifications
You must be signed in to change notification settings - Fork 471
Use normalized string in getByText error if text not found #450
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
Comments
The error message shows the text you put in and the elements. The input isn't normalized. The text of the nodes is normalized. Are you proposing to list the possible values for which the input would return a value? |
@eps1lon Ah I see - misunderstanding on my part. In that case I think the confusion is coming from the rendered DOM not showing the same text as the matcher use, which leads to scenarios where you can see that the text is the same, and directly log out a comparison that shows they're the same, but the matcher still fails. I guess an ideal solution would be to have the rendered DOM normalised based on the same rules the matcher uses - would that be feasible? |
Hmmm... I don't know whether this is possible 😬 Anyone have ideas? |
I'm not sure if this is a misunderstanding of the what the normalizer does or if we can do something. @Cerden Could you add a code example where you think the error message is misleading? |
@eps1lon App.js
App.test.js
The part that's misleading to me is that the text that the error message can't find and the text that's shown in the rendered DOM are the same. Ideally (IMO) it should be clearer that the text in the node has been normalised and so the matcher isn't matching against the same string that was originally passed in. |
@Cerden Thanks. Do you think it's enough the expand the error message to
? |
Just piping in a couple months later: I have this issue & request as well, and that suggestion looks great to me @eps1lon. 😄 |
🎉 This fix is included in version 8.12.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Describe the feature you'd like:
When
getByText
fails to find text that has been normalized, the error message should show the normalized version of the string instead of the original.Currently the error message shows the original un-normalized version. This can be confusing as often that exact text can be seen in the DOM logged out afterwards.
A downside is that it might not be immediately obvious why different text is being shown in the error from what was typed. IMO, if the user is unaware of the default normalization behaviour, this scenario makes it easier to track it down in the docs, and is slightly more representative of why the test is failing.
Describe alternatives you've considered:
Possible alternative is to generically mention normalisation in the error message (alongside text being split onto two lines)
Teachability, Documentation, Adoption, Migration Strategy:
N/A
The text was updated successfully, but these errors were encountered: