-
Notifications
You must be signed in to change notification settings - Fork 273
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
fix: queryByText and getByText match newlines and tabs properly #984
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I think this change makes sense, I believe it would get us away from @testing-library/react
, which doesn't do such normalisation afaik. Do we think it's an ok tradeoff?
@AugustinLF That is because React Web an RN handle whitespace in JSX differently. In RW it uses HTML whitespace policy, that is, to ignore whitespace. However, RN respects whitespace inside |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AugustinLF Looking at the code it seems that we should match Line1\nLine2' when
Textcomponent contains the same very same text content. Before this PR we normalised text but did not normalize the the text matcher string which caused the
normalizedText === matcher` check to fail.
As a general comment, regex text queries are more powerful and don't require perfect matching when using e.g. |
86a036d
to
6a6111d
Compare
6a6111d
to
11ab803
Compare
Rebased and applied suggestions from comments.
I know but here its important, that the formatting is matched exactly, as it has direct visual consequences in RN Text elements unlike React Web. |
@thymikee @AugustinLF We're looking for a second approval for this PR. Can you help? |
Summary
This fixes #983.
New lines, that are rendered in RN as separate Lines, are wrongly normalised during testing.
Test plan
I have added 2 new tests to verify the fix is working.