Enzyme: Question - getting only direct children

Created on 20 Aug 2018  Â·  6Comments  Â·  Source: enzymejs/enzyme

How can I get only the direct children of a node?

question

Most helpful comment

try root.children().filter(‘ul’)

All 6 comments

More context would be helpful, but .children()?

Ok, my problem is that children () returns all descendants of a node, the full hierarchy, while I want to check only the immediate children, i.e., the nodes on the next level at the tree.

@lhsantos .children() should only return the direct children; but those themselves have their own children. Can you step back a bit and explain what you're trying to check for?

Well, for instance, I called root.children('ul') and it returned the immediate child that's a 'ul', but also a grandchild of that node that's also a 'ul'.

try root.children().filter(‘ul’)

ok, sorry for the late response. i'm not completely sure of what i was doing wrong, but i think now i understand how this works. thanks!

Was this page helpful?
0 / 5 - 0 ratings