Jest: React Native Snapshots schlagen mit "TypeError: Cannot read property '_tag' of undefined" für Komponenten fehl, die . enthalten<textinput/>

Erstellt am 6. Aug. 2016  ·  3Kommentare  ·  Quelle: facebook/jest

Fortpflanzen:

  1. Ändern Sie https://github.com/facebook/jest/blob/master/examples/react-native/Intro.js , um einen <TextInput /> in render() hinzuzufügen.
  2. npm-Test

Ergebnis:

FAIL- Tests /Intro-test.js (0,459s)
● Intro › es wird richtig gerendert

  • TypeError: Eigenschaft '_tag' von undefined kann nicht gelesen werden
    bei 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)
    bei 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)
    bei ReactCompositeComponentMixin.mountComponent (node_modules/react/lib/ReactCompositeComponent.js:262:21)
    at Object.ReactReconciler.mountComponent (node_modules/react/lib/ReactReconciler.js:47:35)
    bei ReactMultiChild.Mixin.mountChildren (node_modules/react/lib/ReactMultiChild.js:242:44)
    at ReactTestComponent.mountComponent (node_modules/react/lib/ReactTestRenderer.js:53:8)

Hilfreichster Kommentar

Per https://facebook.github.io/jest/docs/tutorial-react-native.html#mock -native-modules-using-jest-mock besteht die Problemumgehung darin, hinzuzufügen

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

zum Anfang Ihres Tests.

Alle 3 Kommentare

Per https://facebook.github.io/jest/docs/tutorial-react-native.html#mock -native-modules-using-jest-mock besteht die Problemumgehung darin, hinzuzufügen

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

zum Anfang Ihres Tests.

Wir sollten einen Standardmock für TextInput bereitstellen.

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen