Hi,
This is very easy to replicate:
mount(<div>B<span></span></div>).children();
throws this error:
TypeError: renderedChildren[key].getPublicInstance is not a function
at node_modules/enzyme/build/MountedTraversal.js:153:40
at Array.map (native)
at node_modules/enzyme/build/MountedTraversal.js:149:12
at childrenOfInstInternal (node_modules/enzyme/build/MountedTraversal.js:156:6)
at childrenOfInstInternal (node_modules/enzyme/build/MountedTraversal.js:135:12)
at childrenOfInst (node_modules/enzyme/build/MountedTraversal.js:179:10)
at ReactWrapper.<anonymous> (node_modules/enzyme/build/ReactWrapper.js:818:55)
at node_modules/enzyme/build/ReactWrapper.js:1190:21
at Array.map (native)
at ReactWrapper.flatMap (node_modules/enzyme/build/ReactWrapper.js:1189:32)
at ReactWrapper.children (node_modules/enzyme/build/ReactWrapper.js:817:32)
at Object.<anonymous> (test/mount.test.js:34:329)
at process._tickCallback (internal/process/next_tick.js:103:7)
Maybe because of the text node not having a public instance.
I'm using Jest and Enzyme v2.4.1.
Thanks for the report @adriantoine, I was able to reproduce. You are exactly right, we make an unguarded call to getPublicInstance. Looks like we're assuming all rendered children will have a getPublicInstance method, but internally React represents text nodes using ReactDOMTextComponent which does not provide that method.
We should be filtering out these nodes. I'll get a fix in for this soon 馃憤
Cool, thanks! 馃槉
Hey, any update on this? I'm finding a similar issue trying to use parent()
@NealJMD I just merged https://github.com/airbnb/enzyme/pull/604 which should address this
Most helpful comment
Thanks for the report @adriantoine, I was able to reproduce. You are exactly right, we make an unguarded call to
getPublicInstance. Looks like we're assuming all rendered children will have agetPublicInstancemethod, but internally React represents text nodes usingReactDOMTextComponentwhich does not provide that method.We should be filtering out these nodes. I'll get a fix in for this soon 馃憤