How to import jest?

旧巷老猫 提交于 2019-12-21 06:56:07

问题


I would like to get rid of globals in my jest test code. Specifically describe, it and expect

describe('Welcome (Snapshot)', () => {
  it('Welcome renders hello world', () => {
     ...
  });
});

So I tried add

import {describe,it} from 'jest';

and

import jest from 'jest';

jest.describe( ... 
  jest.it( ... 

and other variations..

But no luck.

How should I get it working?


回答1:


The simplest solution for this is adding jest: true to your env config in eslint, like so:

"env": {
  "browser": true,
  "node": true,
  "jasmine": true,
  "jest": true,
  "es6": true
},



回答2:


After I realized jest is running in node, it realized I could do this:

let { describe, it } = global;

Not perfect, but one step closer.. now I don't need to configure my linter with globals anymore.



来源:https://stackoverflow.com/questions/41324636/how-to-import-jest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!