【发布时间】:2021-04-09 18:54:09
【问题描述】:
我收到了错误:
ReferenceError: Cannot access 'myMock' before initialization
我正在这样做:
import MyClass from './my_class';
import * as anotherClass from './another_class';
const mockMethod1 = jest.fn();
const mockMethod2 = jest.fn();
jest.mock('./my_class', () => {
return {
default: {
staticMethod: jest.fn().mockReturnValue(
{
method1: mockMethod1,
method2: mockMethod2,
})
}
}
});
你可以看到我的两个变量都遵守“标准”,但没有正确提升。
我错过了什么吗?
当我只传递 jest.fn() 而不是我的变量时,它显然有效,但我不确定以后如何在我的测试中使用这些。
【问题讨论】:
标签: javascript node.js typescript unit-testing jestjs