我在使用模拟孩子测试组件时遇到错误。因此,我要测试的组件 A 有一个组件 B 作为子组件,而组件 C 作为子组件。我正在尝试模拟 C 组件。以下是 C 在其源文件中的样子:
// C.js
export class C extends React.Component {
constructor(props) {
super(props);
autoBind(this);
}
// ... code ...
}
在我的 A.test.js 中,我有以下内容
jest.mock('<PATH_TO_C.JS>', () => ({
C: jest.fn(() => '')
})
在运行测试时,我收到指向我的自定义渲染的错误:TypeError: Cannot read property 'prototype' of undefined