酶适配器错误 - 无法将未定义或 null 转换为对象
我正在尝试使用 Enzyme 来测试我的 React 应用程序,但遇到了此错误。我没有在其他地方看到过它,也无法弄清楚。
这是堆栈跟踪:
TypeError: Cannot convert undefined or null to object
at hasOwnProperty (<anonymous>)
at Object.<anonymous> (../node_modules/react-shallow-renderer/cjs/react-shallow-renderer.js:54:21)
at Object.<anonymous> (../node_modules/react-shallow-renderer/index.js:3:18)
at Object.<anonymous> (../node_modules/react-test-renderer/shallow.js:3:18)
这是我的测试中导致它的代码。
const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-15');
Enzyme.configure({ adapter: new Adapter() });
..... rest of test file
来自 package.json 的依赖项
"react": "15.6.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-15": "^1.4.3",
I am trying to use Enzyme to test my React application and I'm coming across this error. I haven't seen it mentioned anywhere else and can't figure it out.
Here is the stack trace:
TypeError: Cannot convert undefined or null to object
at hasOwnProperty (<anonymous>)
at Object.<anonymous> (../node_modules/react-shallow-renderer/cjs/react-shallow-renderer.js:54:21)
at Object.<anonymous> (../node_modules/react-shallow-renderer/index.js:3:18)
at Object.<anonymous> (../node_modules/react-test-renderer/shallow.js:3:18)
Here is the code from my test which is causing it.
const Enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-15');
Enzyme.configure({ adapter: new Adapter() });
..... rest of test file
Dependencies from package.json
"react": "15.6.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-15": "^1.4.3",
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论