Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSCode Intellisense is not suggesting available methods in JEST #440

Closed
kartheektrilochan opened this issue Mar 31, 2019 · 28 comments
Closed

Comments

@kartheektrilochan
Copy link

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
    +-- [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
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.

@sewbacca
Copy link

sewbacca commented Apr 1, 2019

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

@dlee005c
Copy link

dlee005c commented Apr 16, 2019

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

@cassiobock
Copy link

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

@filipeestacio
Copy link

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?

@Waserman
Copy link

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.

@redeemefy
Copy link

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.

@noxasch
Copy link

noxasch commented Nov 5, 2019

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

@danielo515
Copy link

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

@redeemefy
Copy link

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.

@NanddoSalas
Copy link

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

@jjayaraman
Copy link

jjayaraman commented Feb 22, 2020

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

@or4
Copy link

or4 commented Feb 28, 2020

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

@jcairo
Copy link

jcairo commented Mar 31, 2020

Including the test folder in tsconfig fixed it for me.

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

@andmill
Copy link

andmill commented Apr 3, 2020

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

@jcairo
Copy link

jcairo commented Apr 3, 2020

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

@leaveswoods
Copy link

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

@sumeetchawla
Copy link

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.

@azad21012
Copy link

azad21012 commented May 26, 2020

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

@onuriltan
Copy link

onuriltan commented Jun 20, 2020

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

olavfosse added a commit to olavfosse/fullstackopen-2020-blog-list that referenced this issue Jul 13, 2020
According to
jest-community/vscode-jest#440 (comment)
installing @types/jest fixes Jest autocompletion. That was the case for me.
@jvmazagao
Copy link

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.

@Mr-Kuzmenko-K
Copy link

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

lesiak added a commit to lesiak/react-udemy-maximilian-schwarzmuller that referenced this issue Oct 13, 2020
lesiak added a commit to lesiak/react-udemy-maximilian-schwarzmuller that referenced this issue Oct 13, 2020
lesiak added a commit to lesiak/react-udemy-maximilian-schwarzmuller that referenced this issue Oct 13, 2020
lesiak added a commit to lesiak/react-udemy-maximilian-schwarzmuller that referenced this issue Oct 26, 2020
lesiak added a commit to lesiak/react-udemy-maximilian-schwarzmuller that referenced this issue Oct 26, 2020
@yevhen-logosha
Copy link

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

@dil-dbakker
Copy link

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.

@aardvarkk
Copy link

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

@alonsogchparra
Copy link

alonsogchparra commented Mar 11, 2021

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

@connectdotz
Copy link
Collaborator

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

@wbolduc
Copy link

wbolduc commented Apr 20, 2021

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

@gianluca-sabena
Copy link

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.

@jest-community jest-community locked and limited conversation to collaborators May 4, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests