【发布时间】:2020-03-13 15:56:12
【问题描述】:
请检查以下场景
const url = 'https://mock.com/mockpath';
jest.mock('../../src/somefile', () => {
return ({
getURL: jest.fn(() => url),
});
});
我遇到错误
babel-plugin-jest-hoist: The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables.
Invalid variable access: url
【问题讨论】:
-
你用的是什么版本?它是你的测试中的佼佼者吗?名称以
mockshould be allowed开头的变量 -
非常感谢,我的变量前面没有模拟。刚刚添加了模拟并解决了问题。
-
所有赞美@skyboyer !说真的,谢谢。
标签: reactjs unit-testing mocking jestjs