Skip to content

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.

2 participants