vscode automatic type acquisition for jest

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


I tried installing the @types/jest, and it did work, but the problem is that it resulted in the jest suggestions appearing in my .js files as well. I couldn't figure out how to get global suggestions for test, expect, etc. in only .test.js files but not .js files.

So I decided to just manually import each jest global I was going to use in each .test.js file, which allowed the suggestions to appear with types but avoided having the suggestions appear in the .js files:

import { test, expect } from '@jest/globals'