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

React Native snapshots fail with "TypeError: Cannot read property '_tag' of undefined" for components containing <TextInput> #1384

Closed
emmby opened this issue Aug 5, 2016 · 4 comments

Comments

@emmby
Copy link

emmby commented Aug 5, 2016

To reproduce:

  1. Modify https://github.com/facebook/jest/blob/master/examples/react-native/Intro.js to add a <TextInput /> in render()
  2. npm test

Result:

FAIL tests/Intro-test.js (0.459s)
● Intro › it renders correctly

  • TypeError: Cannot read property '_tag' of undefined
    at ReactNativeBaseComponent.Mixin.mountComponent (node_modules/react/lib/ReactNativeBaseComponent.js:179:45)
    at Object.ReactReconciler.mountComponent (node_modules/react/lib/ReactReconciler.js:47:35)
    at ReactCompositeComponentMixin.performInitialMount (node_modules/react/lib/ReactCompositeComponent.js:397:34)
    at ReactCompositeComponentMixin.mountComponent (node_modules/react/lib/ReactCompositeComponent.js:262:21)
    at Object.ReactReconciler.mountComponent (node_modules/react/lib/ReactReconciler.js:47:35)
    at ReactCompositeComponentMixin.performInitialMount (node_modules/react/lib/ReactCompositeComponent.js:397:34)
    at ReactCompositeComponentMixin.mountComponent (node_modules/react/lib/ReactCompositeComponent.js:262:21)
    at Object.ReactReconciler.mountComponent (node_modules/react/lib/ReactReconciler.js:47:35)
    at ReactMultiChild.Mixin.mountChildren (node_modules/react/lib/ReactMultiChild.js:242:44)
    at ReactTestComponent.mountComponent (node_modules/react/lib/ReactTestRenderer.js:53:8)
@emmby
Copy link
Author

emmby commented Aug 5, 2016

Per https://facebook.github.io/jest/docs/tutorial-react-native.html#mock-native-modules-using-jest-mock, the workaround is to add

jest.mock('TextInput', () => 'TextInput');

to the beginning of your test.

@cpojer
Copy link
Member

cpojer commented Aug 9, 2016

We should provide a default mock for TextInput.

@cpojer
Copy link
Member

cpojer commented Aug 30, 2016

Fixed in #1516 for Jest 15.

@cpojer cpojer closed this as completed Aug 30, 2016
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants