请检查以下情况
const mockURL = 'https://mock.com/mockpath';
jest.mock('../../src/somefile', () => {
return ({
getURL: jest.fn(() => mockURL ),
});
});
我遇到错误
babel-plugin-jest-hoist: The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables.
Invalid variable access: mockURL
`jest.mock()` is not allowed to reference any out-of-scope variables.
无效的变量访问:mockURL
告诉您jest.mock()
正在尝试访问mockURL
,但不允许其访问范围外的变量。]>
您应该在mockURL
函数调用中声明jest.mock()
:
jest.mock('../../src/somefile', () => {
const mockURL = 'https://mock.com/mockpath';
return ({
getURL: jest.fn(() => mockURL ),
});
});