小编vnx*_*xyz的帖子

无法访问 jest.mock 函数中的变量

请检查以下场景

const url = 'https://mock.com/mockpath';
jest.mock('../../src/somefile', () => {
  return ({
    getURL: jest.fn(() => url),
  });
});
Run Code Online (Sandbox Code Playgroud)

我收到错误

babel-plugin-jest-hoist: The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables.
Invalid variable access: url
Run Code Online (Sandbox Code Playgroud)

unit-testing mocking reactjs jestjs

6
推荐指数
1
解决办法
9954
查看次数

标签 统计

jestjs ×1

mocking ×1

reactjs ×1

unit-testing ×1