27
votes

I have vscode 1.9 and I want to have intellisense for jest tests. The problem is that describe, it, expect etc are globally available in jest and you don't need to import them in your test files. So vscode will not show intellisense for them.

Is there any configuration for globals for automatic type acquisition?

2

2 Answers

58
votes

You have a few options in this case:

Add jest to your package.json:

"dependencies": {
  "jest": "^18.1.0"
}

This only works if you are working JavaScript and do not have a tsconfig.json.


Install @types/jest

$ npm install -D @types/jest

This should work for both JavaScript and TypeScript projects. However @types but may be disabled by a jsconfig.json/tsconfig.json: http://www.typescriptlang.org/docs/handbook/tsconfig-json.html


Create a jsconfig.json file in the root of your workspace to specifically include jest:

{
    "typeAcquisition": {
        "include": [
            "jest"
        ]
    }
}

This will only work for JavaScript projects when automatic typings acquisition is enabled.

All of these should allow VSCode to pick up jest's typings without an import or require

0
votes

npm install -D @types/jest

edit jest.config.js

  typeAcquisition: {
    include: ['jest'],
  },