Setting up Visual Studio Code intellisense for Jest globals

VS Code can't automatically find Jest globals for intellisense, but you can change that.

One of the benefits of Visual Studio Code is it’s ability to automatically detect the type of JavaScript value you’re working with and provide autocomplete (aka intellisense) for properties and methods. This works really well whenever you’re using a module system and explicitly importing values from modules. If a framework happens to add random global variables, however, Visual Studio Code has no way to determine that on its own.

Jest, the JavaScript testing framework, works by injecting several variables (such as describe(), test(), and inspect()) that Visual Studio Code doesn’t know anything about by default. Fortunately, you can tell Visual Studio Code about these globals by creating a jsconfig.json file in the root directory of your project and adding the following into the file:

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

This instructs to look at the jest module for type definitions. With this configuration setup in jsconfig.json, Visual Studio Code will now have intellisense for all of the Jest globals. (Note: You must have the jest npm package installed for this to work.)

Understanding JavaScript Promises E-book Cover

Demystify JavaScript promises with the e-book that explains not just concepts, but also real-world uses of promises.

Download the Free E-book!

The community edition of Understanding JavaScript Promises is a free download that arrives in minutes.