我有这个代码:
import * as a from 'a-a';
jest.mock('a-a');
describe('a-a', () => {
beforeAll(async () => {
const x = await a.x(1); // Calls the mock
console.log(x); // 1
console.log(a.x.mock) // Undefined
});
});
模拟函数是:
export async function x(data) {
cache.push(data);
console.log('HERE'); // this is printed
return data;
}
模块的模拟在__mocks__
目录中。
a.x()
调用模拟函数,但a.x.mock
未定义。
这怎么可能?房产在哪里.mock
?