如何导入Jest? [英] How can I import Jest?
本文介绍了如何导入Jest?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想摆脱Jest测试代码中的全局变量.特别是describe
,it
和expect
:
I would like to get rid of global variables in my Jest test code. Specifically describe
, it
and expect
:
describe('Welcome (Snapshot)', () => {
it('Welcome renders hello world', () => {
...
});
});
所以我尝试添加:
import {describe,it} from 'jest';
和
import jest from 'jest';
jest.describe( ...
jest.it( ...
还有其他变化...
但是没有运气.
我应该如何使其正常工作?
How should I get it working?
推荐答案
当我意识到Jest在Node.js中运行后,它意识到我可以做到这一点:
After I realized Jest is running in Node.js, it realized I could do this:
let { describe, it } = global;
这不是完美的,但是又往前走了一步……现在,我不再需要为全局变量配置linter.
It is not perfect, but one step closer... now I don't need to configure my linter with global variables any more.
这篇关于如何导入Jest?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文