Jest: React Native snapshots gagal dengan "TypeError: Cannot read property '_tag' of undefined" untuk komponen yang mengandung<textinput/>

Dibuat pada 6 Agu 2016  ·  3Komentar  ·  Sumber: facebook/jest

Untuk mereproduksi:

  1. Ubah https://github.com/facebook/jest/blob/master/examples/react-native/Intro.js untuk menambahkan <TextInput /> di render()
  2. tes npm

Hasil:

Tes GAGAL /Intro-test.js (0,459 detik)
● Intro ditampilkan dengan benar

  • TypeError: Tidak dapat membaca properti '_tag' dari undefined
    di ReactNativeBaseComponent.Mixin.mountComponent (node_modules/react/lib/ReactNativeBaseComponent.js:179:45)
    di Object.ReactReconciler.mountComponent (node_modules/react/lib/ReactReconciler.js:47:35)
    di ReactCompositeComponentMixin.performInitialMount (node_modules/react/lib/ReactCompositeComponent.js:397:34)
    di ReactCompositeComponentMixin.mountComponent (node_modules/react/lib/ReactCompositeComponent.js:262:21)
    di Object.ReactReconciler.mountComponent (node_modules/react/lib/ReactReconciler.js:47:35)
    di ReactCompositeComponentMixin.performInitialMount (node_modules/react/lib/ReactCompositeComponent.js:397:34)
    di ReactCompositeComponentMixin.mountComponent (node_modules/react/lib/ReactCompositeComponent.js:262:21)
    di Object.ReactReconciler.mountComponent (node_modules/react/lib/ReactReconciler.js:47:35)
    di ReactMultiChild.Mixin.mountChildren (node_modules/react/lib/ReactMultiChild.js:242:44)
    di ReactTestComponent.mountComponent (node_modules/react/lib/ReactTestRenderer.js:53:8)

Komentar yang paling membantu

Per https://facebook.github.io/jest/docs/tutorial-react-native.html#mock -native-modules-using-jest-mock , solusinya adalah menambahkan

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

ke awal tes Anda.

Semua 3 komentar

Per https://facebook.github.io/jest/docs/tutorial-react-native.html#mock -native-modules-using-jest-mock , solusinya adalah menambahkan

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

ke awal tes Anda.

Kita harus menyediakan tiruan default untuk TextInput.

Diperbaiki di https://github.com/facebook/jest/pull/1516 untuk Jest 15.

Apakah halaman ini membantu?
0 / 5 - 0 peringkat

Masalah terkait

jardakotesovec picture jardakotesovec  ·  3Komentar

kentor picture kentor  ·  3Komentar

rosiakr picture rosiakr  ·  3Komentar

paularmstrong picture paularmstrong  ·  3Komentar

excitement-engineer picture excitement-engineer  ·  3Komentar