如何导入 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( ...
还有其他变体...
但没有运气.
我应该如何让它工作?
推荐答案
在我意识到 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屋!
查看全文