-
Notifications
You must be signed in to change notification settings - Fork 273
Ability to traverse host component tree easily (discussion) #520
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
Comments
Something that I noticed recently is that As such, I'm leaning towards creating (re-creating?) an abstraction on top of ReactTestInstance that would encourage traversing host components and still allow for those "unsafe" use cases. |
We were using some parentNode traversing with RN/TL to assert that some components such as inputs were in the correct validation state, given a certain input e.g. select input, change text, traverse to input error message - confirm that text and text color are correct etc. I think using snapshots would make sense here in a component unit test, but for form integration tests (that combine data, multiple inputs and validation steps) I would rather avoid snapshots and simply traverse the dom to confirm some key details. Perhaps there is a better approach? What I preferred about RN/TL was that it rendererd an abstraction that was closer to what user would see, so making assertions that were user-oriented were easier. I would rather test outcomes like colors than implementation details like a "valid" prop. This is still often (not always) possible with the RNTL dom rendering, but makes testing like this more difficult. |
Closing as stale. |
Describe the Feature
Currently the render tree provided by
render
method consists of both host (e.g.View
) and composite components (class & functional components). All query methods generally ignore composite components, and return only host components, in order to simulate RN runtime env. However, when usingparent
&children
properties ofReactTestInstance
developer using RNTL is exposed to them.RN/TL provided abstraction over component tree wrapping host components'
ReactTestInstance
withNativeTestInstance
in order to allowparent
&children
traversing.RTL does avoid this problem, as it renders using React DOM with JS DOM as runtime env, which leaves only HTML components (which could be equal to host components).
Originally this was raised by @TAGraves in #477:
Possible Implementations
Provide component tree consisting only of host components. This might prove complex due to need to rewire various event handler props like
onPress
from composite components.Provide additional properties (e.g.
parentNode
,childNodes
?) that will skip composite components.Discourage using
parent
andchildren
traversing in favor of higher level abstraction, that better matches 'what the user sees' philosophy.children
traversing can be quite easily replaced withwithin
in many cases. However, there is not easy replacement for ancestor traversing.Build some kind of npm package to focus on simulating RN runtime env, just like JS DOM simulates browser env. It would probably be on React Test Renderer. With this, we could move some runtime env. simulation features from RNTL to that package.
Related Issues
#477
CC: @thymikee, @TAGraves, @cross19xx
@TAGraves could you describe major testing cases which were using
parentNode
traversing, so we can discuss the use cases in more concrete way?The text was updated successfully, but these errors were encountered: