我有一个可以说 file.js 有这样的代码
const myFunc = () => {
return {
func1: () => {},
func2: () => {}
}
}
export const myObject = {
key: ''
};
export default myFunc();
我试图在我的测试中使用 jest 来模拟这个导出。可以说 file.test.js 是测试文件。
jest.mock('./path/file', () => {
return {
default: {
func1: jest.fn(),
func2: jest.fn()
},
myObject: {}
};
});
但是当我的测试运行时,它会抛出错误说_File.default.func1 is not a function。
如何正确模拟具有默认导出和命名导出的 js 文件?