vscode-jest: VSCode Intellisense is not suggesting available methods in JEST

Environment

  1. node -v: v.9.2.0

  2. npm -v: 5.5.1

  3. npm ls jest or npm ls react-scripts (if you haven’t ejected): npm ls jest ±- jest@24.5.0 -- react-scripts@2.1.8 – jest@23.6.0

  4. your vscode-jest settings if customized:

    • jest.pathToJest? [fill]
    • jest.pathToConfig? [fill]
    • anything else that you think might be relevant? [fill]
  5. Operating system: Windows_NT x64 10.0.17134

Prerequisite

  • are you able to run jest test from command line? yes
  • how do you run your tests from command line? npm run test

Steps to Reproduce:

Create a new react app using

1 .npx create-react-app my-app 2. npm install --save-dev jest 3. Opened the project in VSCode.

Expected Behavior

I expect VS Code intellisense would assist me with available methods from JEST.

Actual Behavior

VS Code is not suggesting me any method suggestions for JEST test cases.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 30
  • Comments: 28

Commits related to this issue

Most upvoted comments

I’m having the same problem. I’ve tried installing @types/jest with npm i @types/jest and the suggestions started to show again.

create jsconfig.json in the root directory of your project. the file should contain the following: { "typeAcquisition": { "include": [ "jest" ] } }

after saving reload vscode. Worked for me.

I found that I need to restart vscode after installing @types/jest if vscode was open during installation. Can anyone confirm if that is expected?

I’m having the same problem. I’ve tried installing @types/jest with npm i @types/jest and the suggestions started to show again.

mine only works after i install @types/jest as suggested

node v10.15.0 npm v6.5.0

npm i -D @types/jest

P.S Doing both steps worked for me, and the last one 🙂

  1. npm i -D @types/jest
  2. Add jsconfig.json to root folder as
{
    "typeAcquisition": {
        "include": ["jest"]
    }
}
  1. Reload VSCode

Install @types/jest as a dev dependencie works for me. I’ve tried to install it globally but it seems not work.

None of the provided solutions works for me. Guess what else can I try

create jsconfig.json in the root directory of your project. the file should contain the following: { "typeAcquisition": { "include": [ "jest" ] } }

after saving reload vscode. Worked for me.

For some reason this solution doesn’t work for me. Interesting is that I found a post from Nicholas Zakas post with the solution you are proposing. I’m wondering if I need to tell vscode about jsconfig.json or doesn vscode just picked it up if its there.

Including the test folder in tsconfig fixed it for me.

... "include": ["src", "test"]

My case was opening VSCode at the root of our repo, rather than the src folder which contained our jest.config.js and tsconfig.json files. When I opened the src folder as a VSCode Project, everything worked as expected.

P.S Doing both steps worked for me, and the last one 🙂

  1. npm i -D @types/jest
  2. Add jsconfig.json to root folder as
{
    "typeAcquisition": {
        "include": ["jest"]
    }
}
  1. Reload VSCode

In my vscode this solution works very well.

Installing @types/jest solved the problem while adding this to jsconfig.js could not help { "typeAcquisition": { "include": ["jest"] } }

Including the test folder in tsconfig fixed it for me.

... "include": ["src", "test"]

This worked for me too. I have the orta.vscode-jest extension installed and am running a react 16 project with npx create-react-app. No restart of VSCode required

install local and global types, works fine npm i @types/jest npm i -g @types/jest

Thanks, Guys, as mentioned above just the below in jsconfig.json works for me. I thought in javascript projects this is a better option, as javascript project like ReactJS does not need to install @types/xxxx. I guess @types are only for typescript projects?

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

Another workaround is to use explicit import: "However, if you prefer explicit imports, you can do import {describe, expect, test} from ‘@jest/globals’."as documented here https://jestjs.io/docs/api

PS: I was not able to solve the problem with other suggest methods.

None of the provided solutions works for me. Guess what else can I try

Try to create a new user in your computer with a fresh installation of vscode and do npm i -D @types/jest and see if that works. I’m just trying to isolate all other extensions that might be causing conflict.