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

Created on 31 Mar 2019  路  28Comments  路  Source: jest-community/vscode-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鈥檛 ejected):
    npm ls jest
    +-- [email protected]
    -- [email protected] -- [email protected]

  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

  1. npm install --save-dev jest
  2. 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.

Most helpful comment

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

All 28 comments

I'm facing the same problem. Testing works fine, but methods aren't suggested.
npm -v: 6.5.0
node -v: v11.9.0

same for me as well.
node -v v9.6.1
npm -v 6.9.0
vscode: version 1.33.1 (1.33.1)
For what it's worth, i'm using nvm to manage node/npm

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

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?

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.

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.

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

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

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.

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

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"]
    }
}

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

Including the test folder in tsconfig fixed it for me.

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

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

Only problem is that it then compiles the code test project folder. Still not a great solution...

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

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?

Yup, yesterday it wasn't working. I closed and went to sleep and it is working now. I did a lot of window reload yesterday but didn't work either.

before read this issue i thought need an extension like jest -published by orta- . but after installing @types/jest and reload vs-code the methods suggested successfully by vs-code :)

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

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.

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

Dude, thank you so much

my case was an outdated version of @types/jest, upgrading it to match version of Jest did the trick

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.

@dil-dbakker Thank you! This was exactly my problem. I tried about a thousand complicated config options people were proposing but I was just one directory "too high" opening a parent directory in VSCode. Running vscode . inside the specific project I was working with fixed everything for me.

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.

This suggestion worked for me very well. Thanks for the feedback @Waserman

great thread to help people resolving similar issues. But since this issue is really not related to this extension, I will close it.

great thread to help people resolving similar issues. But since this issue is really not related to this extension, I will close it.
Where would you recommend this information goes

I was experiencing this same sort of problem where intellisense would not show the available jest methods despite doing what almost every thread on the topic suggests

I was able to resolve it but I don't know why this works.

_remove_ { "typeAcquisition": { "include": [ "jest" ] } }
make sure that in the jsconfig.json you are not specifying a compilerOption.target

My resulting config looks like this (minus work specific stuff)
{ //for some reason type acquisition and and target both break intellisense for jest "compilerOptions": { "allowSyntheticDefaultImports": false, "baseUrl": "./", "paths": { "Test/*": ["./__mocks__/*"] } }, "include": ["./src/**/*"] }

The packages I have installed relevant to testing
"@testing-library/jest-dom": "^5.11.10", "@testing-library/react": "^11.2.6", "@testing-library/user-event": "^13.1.3", "@types/jest": "^26.0.22", "@types/react": "^17.0.3", "babel-jest": "^26.6.3", "babel-plugin-transform-class-properties": "^6.24.1", "eslint-plugin-jest": "^24.3.5", "jest": "^26.6.3", "jest-dom": "^4.0.0", "msw": "^0.28.1",

I don't totally know why this works but it's worth a shot if you were stuck like me

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jackfranklin picture jackfranklin  路  19Comments

erikns picture erikns  路  16Comments

Cael6 picture Cael6  路  19Comments

connectdotz picture connectdotz  路  24Comments

karb0f0s picture karb0f0s  路  37Comments