javascript - react-testing-library 渲染功能有什么问题?它在某些对象上返回错误
问题描述
使用:“@testing-library/react”:“^9.1.4”,
如果我打电话:
渲染({组件})
组件在哪里:
{ '$$typeof': Symbol(react.element),
type:
{ mapStateToProps: [Function],
mapDispatchToProps: [Function: mapDispatchToProps],
reactComponent: { [Function: WithHandlers] displayName: 'withHandlers(lifecycle(Component))' },
mockDispatch:
{ [Function: mockConstructor]
_isMockFunction: true,
getMockImplementation: [Function],
mock: [Getter/Setter],
mockClear: [Function],
mockReset: [Function],
mockReturnValueOnce: [Function],
mockReturnValue: [Function],
mockImplementationOnce: [Function],
mockImplementation: [Function],
mockReturnThis: [Function],
mockRestore: [Function] } },
key: null,
ref: null,
props: {},
_owner: null,
_store: {} }
我收到此错误:
console.error node_modules/react/cjs/react.development.js:172 警告:React.createElement:类型无效——需要一个字符串(对于内置组件)或一个类/函数(对于复合组件),但得到:目的。
如果我渲染这个组件没有错误:
{ '$$typeof': Symbol(react.element),
type: [Function],
key: null,
ref: null,
props: {},
_owner: null,
_store: {} }
它们似乎都是 react.elements 和https://testing-library.com/docs/react-testing-library/api暗示这是它所期望的。
我做错了什么?
解决方案
您正在调用render({component})
,根据文档,输入应该是React.ReactElement<any>
。
你试过render(component)
吗?
推荐阅读
- python - 我如何创建返回按钮 tkinter
- ios - SQLite.swift 框架
- python - 为什么在这个函数中使用 self ?
- android - 我创建的本地通知正在立即发送,而不是在我希望发送的日期
- reactjs - Reactjs 团队是否避免实现自己的类似 redux 的状态管理?
- sql-server - 在sql数据库中最后一次出现“_”后获取子字符串值
- r - 展开 scale_x_continuous()
- dbscan - 考虑到 DBSCAN 算法中所有特征对的组合,为什么考虑所有特征不会复制?
- c++ - 如何在 qt 表单设计器的小部件中显示两个不同的类
- ios - 将 NSData 转换为 NSArray