react-native-testing-library icon indicating copy to clipboard operation
react-native-testing-library copied to clipboard

Design an API for providing custom ByText implementation

Open thymikee opened this issue 4 years ago • 5 comments

Describe the Feature

Right now, we rely on grabbing Text from react-native in *ByText queries. We should make it possible for users to replace it with Text from other libraries, like react-native-windows or react-xp. Or make it possible to extend *ByText queries to have a custom implementation.

Possible Implementations

TBD

thymikee avatar May 15 '20 10:05 thymikee

What about implementing something similar to the findAll method described here. It was part of the deprecated native-testing-library and was intended to be used as an escape hatch for selecting elements using a custom callback. It seems pretty hacky but it could be of use in these (and future) cases, as RN is supported in more and more environments.

pplytas avatar Sep 30 '20 16:09 pplytas

I'm not a fan of findAll as I have a hunch that users will abuse it when not necessary, as they tend to do. That's why we're limiting the APIs in the first place. I'm open to discussion though, it's only my personal opinion :)

thymikee avatar Sep 30 '20 16:09 thymikee

TBH I can see how it may do more harm than good. Maybe a stricter API like an extra parameter (e.g. TargetElementType) in *ByText methods would be a safer, more streamlined alternative. Or even a new set of methods e.g *ByCustomText. Just sharing some thoughts as well :)

pplytas avatar Sep 30 '20 19:09 pplytas

@thymikee is this feature request still relevant? Seems like if implemented we would be moving outside of React Native domain and more towards something like React Anything/Test Renderer Testing Library. In such case maybe we should consider extracting common Test Render part and build React Native behaviours on top of it.

mdjastrzebski avatar Aug 08 '22 16:08 mdjastrzebski

This is something I had in mind very early in the design process. Thought it may become useful, but so far it didn't prove really necessary. I'm ok to close this ticket and wait for some real use case that users bump into.

thymikee avatar Aug 11 '22 17:08 thymikee