Closed ghost closed 4 years ago
Hi, thanks for using Testing Library!
Unfortunately, I don’t think we’ll be able to implement this feature. We do have the tools to do it, but it’s not the way text matchers work in the rest of the Testing Library family, and keeping in parity with the rest of the family is a top priority for us. If text is broken up into multiple nodes, it won’t match in React/DOM Testing Library either.
With that in mind, my recommendation would be to take it upstream to DOM Testing Library to get buy in to change it there, or follow the warning given when text can’t be found. If instead of a string or regex match, you pass a callback function as the “text”, you can do custom matching to find text broken up by elements. Two arguments are passed to that callback, here it is in the source if you want to check it out.
Hopefully that helps, and good luck! ☺️
Implemented in v7.0. FYI, this repository is no longer responsible for this package. See the migration guide to v7.0.
Describe the feature you'd like:
Right now,
getNodeText
only checks immediate children for their text content. So code like this is not easily testable:Suggested implementation:
I'd recursively go through the children and merge any arrays in there. Couldn't get anywhere in half an hour but am happy to invest more time if we agree this is a good idea.
Describe alternatives you've considered:
None really
Teachability, Documentation, Adoption, Migration Strategy:
A user will use it the same way as they can already except that it's now recursive so even nested children will be merged.