我有这样的代码:
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
});
});
mock函数是:
export async function x(data) {
cache.push(data);
console.log('HERE'); // this is printed
return data;
}
模块的模拟位于__mocks__
目录中。
a.x()
调用模拟函数,但a.x.mock
是未定义的。
那件事怎么可能?.mock
属性在哪里?
https://stackoverflow.com/questions/44670324
复制相似问题