【发布时间】:2017-01-09 21:02:44
【问题描述】:
在将我的 react-native 0.30 应用程序从 Jest 14.1.0 升级到 15.1.0 后,我开始在大多数(但不是全部)测试中收到以下错误:
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
at invariant (node_modules/fbjs/lib/invariant.js:38:15)
at instantiateReactComponent [as _instantiateReactComponent] (node_modules/react/lib/instantiateReactComponent.js:86:134)
at ReactCompositeComponentMixin.performInitialMount (node_modules/react/lib/ReactCompositeComponent.js:358:22)
at ReactCompositeComponentMixin.mountComponent (node_modules/react/lib/ReactCompositeComponent.js:241:21)
at Object.ReactReconciler.mountComponent (node_modules/react/lib/ReactReconciler.js:49:35)
at ReactCompositeComponentMixin.performInitialMount (node_modules/react/lib/ReactCompositeComponent.js:367:34)
at ReactCompositeComponentMixin.mountComponent (node_modules/react/lib/ReactCompositeComponent.js:241:21)
at Object.ReactReconciler.mountComponent (node_modules/react/lib/ReactReconciler.js:49:35)
at ReactCompositeComponentMixin.performInitialMount (node_modules/react/lib/ReactCompositeComponent.js:367:34)
at ReactCompositeComponentMixin.mountComponent (node_modules/react/lib/ReactCompositeComponent.js:241:21)
at Object.ReactReconciler.mountComponent (node_modules/react/lib/ReactReconciler.js:49:35)
at mountComponentIntoNode (node_modules/react/lib/ReactTestMount.js:47:31)
at ReactTestReconcileTransaction.Mixin.perform (node_modules/react/lib/Transaction.js:138:20)
at batchedMountComponentIntoNode (node_modules/react/lib/ReactTestMount.js:61:27)
at ReactDefaultBatchingStrategyTransaction.Mixin.perform (node_modules/react/lib/Transaction.js:138:20)
at Object.ReactDefaultBatchingStrategy.batchedUpdates (node_modules/react/lib/ReactDefaultBatchingStrategy.js:63:19)
这些都是使用react-test-renderer 的测试,通常如下所示:
import 'react-native'
import React from 'react'
import Foo from '../Foo'
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer'
describe('<Foo />', () => {
it('renders correctly', () => {
const tree = renderer.create(
<Foo loading={false} dispatch={() => {}} />
).toJSON()
expect(tree).toMatchSnapshot()
})
})
这个完全相同的测试文件适用于我的一个组件,但如果我尝试大多数其他组件,则会失败。所有这些测试在 Jest 14.1.0 下都能正常工作。
错误消息的描述性不是很好。你知道会发生什么吗?
【问题讨论】:
标签: reactjs react-native jestjs