-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Easier way to access child refs #361
Copy link
Copy link
Closed
Description
Once in awhile we'll have a test that renders a component P with child C:
<P><C>
<div></div>
<div></div>
</C></P>
To get the second <div> in a test, we'll add a ref to it:
<P><C>
<div></div>
<div ref={'__testDiv'}></div>
</C></P>
//
TestUtils.findRenderedComponentWithType(p, C).refs.testDiv
With enzyme, though, it doesn't seem to be easy to get to that ref
pWrapper.find(C).ref('__testDiv') // Error: ReactWrapper::ref(refname) can only be called on the root
The only alternative has to use css classes, which isn't ideal since that shows up in the final markup. The div itself is pretty hard to select for - is there an easier way I'm missing?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels