我想摆脱 Jest 测试代码中的全局变量。特别 describe
, it
和 expect
:
describe('Welcome (Snapshot)', () => {
it('Welcome renders hello world', () => {
// ...
});
});
所以我尝试添加:
import { describe, it } from 'jest';
和
import jest from 'jest';
jest.describe('Welcome (Snapshot)', () => {
jest.it('Welcome renders hello world', () => {
// ...
});
});
和其他变体,但它不起作用。
我怎样才能让我的 Jest 测试代码在没有全局变量的情况下工作?
原文由 guy mograbi 发布,翻译遵循 CC BY-SA 4.0 许可协议
在我意识到 Jest 在 Node.js 中运行后,它意识到我可以这样做:
它并不完美,但更近了一步……现在我不再需要使用全局变量配置我的 linter。