Skip to content

Support textareas with children #344

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 1 commit into from
Sep 5, 2019

Conversation

amannn
Copy link
Contributor

@amannn amannn commented Aug 22, 2019

What:

Fixes this bug: #343 (comment)

Checklist:

  • Documentation added
  • Typescript definitions updated
  • Tests
  • Ready to be merged

// The children of a textarea are part of `textContent` as well. We
// need to remove them from the string so we can match it afterwards.
label.querySelectorAll('textarea').forEach(textarea => {
textToMatch = textToMatch.replace(textarea.value, '')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm... What if the label is the same as the text value at that moment?

Copy link
Member

Choose a reason for hiding this comment

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

I think we should be able to use label.childNodes[0].textContent here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexkrolick replace only replaces the first occurence:

'abcabc'.replace('abc', '') // "abc"

Therefore this should be fine.

@timdeschryver Sorry, I can't follow? Generally I think it's good to avoid childNodes so we support arbitrary nesting for both the textarea and the label. There could be some divs and spans wrapped around for example.

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.

This is a little odd, but I think I'm ok with this change. I can't think of situations where it would lead to people breaking our goals with testing and it doesn't add anything to the API. It also doesn't really violate the principle of least surprise, so I think I'm good with it. I'd love a 👍 from another maintainer though.

@amannn
Copy link
Contributor Author

amannn commented Aug 30, 2019

Thanks for the review! Is there another maintainer who wants to have a look at this? Would be great to get this fixed, so I can remove a workaround in my code base 🙂. Thanks!

@kentcdodds kentcdodds merged commit f9714ed into testing-library:master Sep 5, 2019
@kentcdodds
Copy link
Member

@all-contributors please add @amannn for code and tests

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @amannn! 🎉

@kentcdodds
Copy link
Member

🎉 This PR is included in version 6.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@amannn amannn changed the title Support textareas with children. Support textareas with children Sep 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants