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.)

Master JavaScript Promises

Free E-book - Understanding JavaScript Promises

What You'll Learn

  • Promise fundamentals and concepts
  • Real-world promise implementations
  • Best practices and patterns
  • Error handling techniques

Demystify JavaScript promises with practical examples and expert insights.

Download Your Free Copy

The community edition arrives in your inbox within minutes.