Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(getNodeText): Don't join text nodes with whitespace #87

Merged
merged 3 commits into from
Aug 10, 2018
Merged

feat(getNodeText): Don't join text nodes with whitespace #87

merged 3 commits into from
Aug 10, 2018

Conversation

bdchauvette
Copy link
Contributor

What:

Changes the way getNodeText joins nodes. Instead of joining them with a space, it now joins them with an empty string.

Why:

This PR comes out of testing-library/react-testing-library#53

In React, if you have an element like <span>{volts}V</span>, then the generated element will have two text nodes, one for the variable volts, and one for the normal string.

When browsers render this, there is no space between the text nodes. Likewise, the textContent property on the span will return a string without spaces (e.g. 300V).

However, the current implementation of getNodeText joins all of the nodes with a space, so if you try to use e.g. queryByText('300V') it will return null.

For a live demo, see https://codesandbox.io/s/w718n5ojq7

How:

Checklist:

  • Documentation - N/A (I think?)
  • Tests
  • Ready to be merged
  • Added myself to contributors table

Thanks! 馃樃

@kentcdodds
Copy link
Member

Thanks for this! I think that I misunderstood something when I created this in the first place. I've verified that this change doesn't break anything on react-testing-library and react-testing-library-examples 馃憤 Thank you again!

@kentcdodds kentcdodds merged commit 8ffe6d6 into testing-library:master Aug 10, 2018
@kentcdodds
Copy link
Member

馃帀 This PR is included in version 3.3.0 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

alexkrolick pushed a commit to alexkrolick/dom-testing-library that referenced this pull request Sep 13, 2018
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.

None yet

2 participants