使用:“@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 Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.
如果我渲染此组件,则不会出现错误:
{ '$$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)
?
关于javascript - React-testing-library 渲染函数有什么问题?它对某些对象返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57962228/