Skip to content

Ignore extra whitespace when matching nodes by text content #19

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

Merged
merged 2 commits into from
Apr 11, 2018
Merged

Ignore extra whitespace when matching nodes by text content #19

merged 2 commits into from
Apr 11, 2018

Conversation

gnapse
Copy link
Member

@gnapse gnapse commented Apr 11, 2018

What:

This fixes testing-library/react-testing-library#53

When matching nodes by their text content, the extra whitespace within words in that text has to be ignored.

Why:

Extra whitespace within text is ignored by browsers when that text is shown to users on screen or even by screen readers. Therefore it is reasonable to assume that when matching nodes by their text content, this should be done as closely as possible to how a user of a web app does it.

How:

Replaced all contiguous whitespace within a text node with a single space, before using that text to match it.

Checklist:

  • Tests
  • Ready to be merged

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! Thank you!

@kentcdodds kentcdodds merged commit 605ded7 into testing-library:master Apr 11, 2018
@gnapse gnapse deleted the pr/ignore-extra-whitespace branch April 11, 2018 14:09
@kentcdodds
Copy link
Member

🎉 This PR is included in version 1.6.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Variables in JSX strings put on new line
2 participants