Jest: import jest functions instead of having globals

Created on 28 Dec 2017  路  7Comments  路  Source: facebook/jest

Feature request or documentation missing?
I'd like to do

import {test, expect} from 'jest'

The current behaviour with globals works but it's just not convenient because IDEs don't recognize the functions.

Here are some stackoverflow related to this:
https://stackoverflow.com/questions/41324636/how-to-import-jest/43964557#43964557
https://stackoverflow.com/questions/41143700/how-to-import-describe-expect-and-it-into-a-typescript-tests-for-ide-to-n

Most helpful comment

We have some vague plans to support it, but nothing concrete at this point. It is a feature we want, though 馃檪

All 7 comments

@apflieger, I find that VSCode works fine if you install the Jest typings.

I couldn't find a way to make it work in IntelliJ

Duplicate of #4473

IDE compatibility is pretty good if you use typings from either flow or typescript

It's also not convenient because it breaks standardjs.
Of course, we can

  • Add global ignore of jest it and other functions in standard config
  • just go for import { it } from global

But I like to think that, if a linter complies, it's because it's a bad practise. And indeed everything in global is a bad practise, at the root of some evils.

Mocha supports it. Any plan to add it ?

We have some vague plans to support it, but nothing concrete at this point. It is a feature we want, though 馃檪

This will be available in the next version of Jest via #9801.

Was this page helpful?
0 / 5 - 0 ratings