Untuk mereproduksi:
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)
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.
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.