Jest: Les instantanés React Native échouent avec "TypeError: Cannot read property '_tag' of undefined" pour les composants contenant<textinput/>

Créé le 6 août 2016  ·  3Commentaires  ·  Source: facebook/jest

Reproduire:

  1. Modifiez https://github.com/facebook/jest/blob/master/examples/react-native/Intro.js pour ajouter un <TextInput /> dans render()
  2. test npm

Résultat:

FAIL tests /Intro-test.js (0.459s)
● Intro › il s'affiche correctement

  • TypeError : impossible de lire la propriété '_tag' d'undefined
    à ReactNativeBaseComponent.Mixin.mountComponent (node_modules/react/lib/ReactNativeBaseComponent.js:179:45)
    à Object.ReactReconciler.mountComponent (node_modules/react/lib/ReactReconciler.js:47:35)
    à ReactCompositeComponentMixin.performInitialMount (node_modules/react/lib/ReactCompositeComponent.js:397:34)
    à ReactCompositeComponentMixin.mountComponent (node_modules/react/lib/ReactCompositeComponent.js:262:21)
    à Object.ReactReconciler.mountComponent (node_modules/react/lib/ReactReconciler.js:47:35)
    à ReactCompositeComponentMixin.performInitialMount (node_modules/react/lib/ReactCompositeComponent.js:397:34)
    à ReactCompositeComponentMixin.mountComponent (node_modules/react/lib/ReactCompositeComponent.js:262:21)
    à Object.ReactReconciler.mountComponent (node_modules/react/lib/ReactReconciler.js:47:35)
    à ReactMultiChild.Mixin.mountChildren (node_modules/react/lib/ReactMultiChild.js:242:44)
    à ReactTestComponent.mountComponent (node_modules/react/lib/ReactTestRenderer.js:53:8)

Commentaire le plus utile

Selon https://facebook.github.io/jest/docs/tutorial-react-native.html#mock -native-modules-using-jest-mock, la solution de contournement consiste à ajouter

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

au début de votre test.

Tous les 3 commentaires

Selon https://facebook.github.io/jest/docs/tutorial-react-native.html#mock -native-modules-using-jest-mock, la solution de contournement consiste à ajouter

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

au début de votre test.

Nous devrions fournir une simulation par défaut pour TextInput.

Corrigé dans https://github.com/facebook/jest/pull/1516 pour Jest 15.

Cette page vous a été utile?
0 / 5 - 0 notes