Jestjs 我怎样才能使用;“之前”;而不是",;在“以前”之前;?

Jestjs 我怎样才能使用;“之前”;而不是",;在“以前”之前;?,jestjs,Jestjs,我正在将现有测试迁移到Jest 我可以用在之前而不是之前开玩笑吗 我要做的是在jest.config.js中 module.exports={ ... 全球:{ 之前:之前,, }, }; 但是我怎么才能在进口之前进口呢要求('@jest/globals')引发: Error: Do not import `@jest/globals` outside of the Jest test environment 无法在Jest配置文件中访问beforeAll,因为它和测试在不同的进程中运行gl

我正在将现有测试迁移到Jest

我可以用
之前而不是之前开玩笑吗

我要做的是在
jest.config.js

module.exports={
...
全球:{
之前:之前,,
},
};
但是我怎么才能在进口之前进口呢<代码>要求('@jest/globals')引发:

Error: Do not import `@jest/globals` outside of the Jest test environment

无法在Jest配置文件中访问beforeAll,因为它和测试在不同的进程中运行
globals
选项用于可序列化的JSON值

正确的位置是在
setupfileafterenv
config选项中指定的文件:

global.before = beforeAll;

谢谢你的回答,埃斯特斯。我在安装文件中尝试了
console.log(require(@jest/globals))
。但它给出了以前未定义的结果。实际上,除了笑话之外,所有的未定义(
{afterAll:undefined,afterEach:undefined,beforeAll:undefined,beforeach:undefined,description:undefined,
…)你知道我怎样才能在setupFile中获得beforeAll吗?你根本不需要
@jest/globals
。更准确地说,这需要在setupfileafterenv中完成,因为那里有完全可用的jest环境。谢谢你的跟进。
setupfileafterenv
可以工作。它非常有用。现在我可以更轻松地迁移到jest