【发布时间】:2018-03-31 14:55:28
【问题描述】:
在升级到 React 16 之前,我进行了很多正常工作的测试,以及对 enzime 和 jest 的相应升级。我关注the instructions 并将这两个文件添加到我的 package.json 中的 jest 配置中
"jest": {
"globals": {
"rootLevel": "/portal"
},
"moduleNameMapper": {
"components": "<rootDir>/../components",
"\\.(jpg|jpeg|png|gif|svg|woff|woff2)$": "<rootDir>/_tests/__mocks/fileMock.js"
},
"setupFiles": [
"<rootDir>/_tests/__config/shim.js",
"<rootDir>/_tests/__config/enzyme-setup.js"
]
}
但我仍然没有看到我的测试运行正常。我的大多数测试都抛出了与此相同的错误:
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.
Check the render method of `WrapperComponent`.
at invariant (node_modules/fbjs/lib/invariant.js:42:15)
...
at mount (node_modules/enzyme/build/mount.js:19:10)
at Object.<anonymous> (_tests/MyTest.test.js:39:35)
所有触发的都是这一行:
const wrapper = mount(<MyComponent {...props} />)
据我所知,mount 在酶 3 中的作用仍然相同。我所有涉及渲染的测试都失败了。我错过了什么?
【问题讨论】: