Skip to content
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

children() throws an error when called on a component having a text node with a span #603

Closed
adriantoine opened this issue Sep 22, 2016 · 4 comments
Labels

Comments

@adriantoine
Copy link

adriantoine commented Sep 22, 2016

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.

@aweary
Copy link
Collaborator

aweary commented Sep 22, 2016

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 👍

@aweary aweary added the bug label Sep 22, 2016
@adriantoine
Copy link
Author

Cool, thanks! 😊

@NealJMD
Copy link

NealJMD commented Jan 9, 2017

Hey, any update on this? I'm finding a similar issue trying to use parent()

@aweary
Copy link
Collaborator

aweary commented Jan 10, 2017

@NealJMD I just merged #604 which should address this

breville added a commit to code-dot-org/code-dot-org that referenced this issue Jul 19, 2017
This should fix a test issue in which it wasn't possible to get children when one of them was a text node (containing a <span>), described at enzymejs/enzyme#603
breville added a commit to code-dot-org/code-dot-org that referenced this issue Jul 19, 2017
This should fix a test issue in which it wasn't possible to get children when one of them was a text node (containing a span), described at enzymejs/enzyme#603
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants