重现:
结果:
失败测试/Intro-test.js (0.459s)
● 介绍 › 它正确呈现
- 类型错误:无法读取未定义的属性“_tag”
在 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)
根据https://facebook.github.io/jest/docs/tutorial-react-native.html#mock -native-modules-using-jest-mock,解决方法是添加
jest.mock('TextInput', () => 'TextInput');
到考试开始。
我们应该为 TextInput 提供一个默认的模拟。
在https://github.com/facebook/jest/pull/1516 中修复了 Jest 15。
最有用的评论
根据https://facebook.github.io/jest/docs/tutorial-react-native.html#mock -native-modules-using-jest-mock,解决方法是添加
jest.mock('TextInput', () => 'TextInput');
到考试开始。