我想删除 Jest 测试代码中的全局变量。具体来说describe
, it
, and expect
:
describe('Welcome (Snapshot)', () => {
it('Welcome renders hello world', () => {
// ...
});
});
所以我尝试添加:
import { describe, it } from 'jest';
and
import jest from 'jest';
jest.describe('Welcome (Snapshot)', () => {
jest.it('Welcome renders hello world', () => {
// ...
});
});
和其他变化,但它不起作用。
如何在没有全局变量的情况下让 Jest 测试代码正常工作?
最简单的解决方案是添加jest: true
给你的env
配置在ESLint https://en.wikipedia.org/wiki/ESLint,像这样:
"env": {
"browser": true,
"node": true,
"jasmine": true,
"jest": true,
"es6": true
},
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)