How can I import Jest?

guy mograbi picture guy mograbi · Dec 25, 2016 · Viewed 21.4k times · Source

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', () => {
     ...
  });
});

So I tried to 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?

Answer

Alejandro Garcia Anglada picture Alejandro Garcia Anglada · May 14, 2017

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

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