Reputation: 1562
I'm working with VSCode and installed the extension: "Jest" for better jest-testing-enviroment.
In the extension's instruction I saw we get a nice intellisense support for Jest's commands.
I dont get "Jest" icon on the bottom bar, which means the ext doesnt work properly.
I still don't get the intellisense support for jest's commands
Has anyone had this issue and found a way to configure it properly ?
Upvotes: 26
Views: 60628
Reputation: 4966
TL;DR inside the root of your workspace, add a .vscode/settings.json
with "jest.rootPath"
set to "."
I encountered this issue while using vscode-jest
. It started happening because I was using multiple workspaces.
I had the following folders:
-foo
-index.ts
-bar
-index.ts
-index.test.ts
And of course, I was trying to run tests inside /bar
Unfortunately, as others have noted, my tests would misbehave.
My solution was to add a bar/.vscode/settings.json
with "jest.rootPath": "."
inside it.
Now, my folders look like this:
-foo
-index.ts
-bar
-.vscode
-settings.json
-index.ts
-index.test.ts
/bar/.vscode/settings.json
contains the following:
{
"jest.rootPath": "."
}
Upvotes: 1
Reputation: 3328
I run Windows 11 and the Jest extension for VS Code started working on installing pre-release version 6.1.0
Then I could see Jest: Run Related Tests
in the dropdown
Upvotes: 0
Reputation: 4649
After wasting lot of time and installing lots of extensions. I found out that we have to install @types/jest
as dev dependency for intellisense to make our intellisense work in VSCode.
npm i -d @types/jest
Note: If installing @type/jest doen't work, try restarting VSCode. I have also attached my package.json fo reference, so that you can match if anything else missing for Jest.
Upvotes: 0
Reputation: 71
On a fresh install of the extension, it didn't work properly for me right out of the box either. Running npm run test
on the WSL2 terminal worked, but the extension didn't.
My folder structure was
root
__tests__
__testThis__
featureA.js <-- jest tests
__andThis__
feature1.js <--
feature2.js <--
testThis.js
andThis.js
package.json
and my test script was initially "test": "jest --watchAll --maxWorkers=1",
on my package.json.
But it finally worked after doing the ff.:
"jest.rootPath": "",
jest --init
at the root of my project to create a jest.config.js. This updates the test script to "test": "jest"
-- I left this as is after.testMatch: [
"**/__tests__/**/*.[jt]s?(x)",
"**/?(*.)+(spec|test).[tj]s?(x)"
],
"jest.autoRun": "off",
Even then, not everything in the extension works perfectly (e.g. the debugger still doesn't work for me), but am able to run single tests (or all tests at once) using the extension.
Hope this helps somehow!
Upvotes: 7
Reputation: 21902
I had the same problem. I just placed a jest.config.js
at the root of my monorepo and the extension picks up. The problem, for me at least, was that it was looking for that file starting at the root path, and never finding it.
Upvotes: 4
Reputation: 5129
Highly recommend using the jest runner extension instead.
Demo:
Upvotes: 12
Reputation: 1562
Once I understood my folder structure was the reason for the extension not to work properly, I started using VSCode's Workspaces.
When using Workspaces you can have multiple projects in one folder. Each will be count as a root project. The Workspace allows you to have multiple root projects in the same folder (which actually solved my problem).
When working with Jest without setting a jest.config.js
file, you get your rootDir
to its default (which is the folder where the package.json
is in).
From what I experienced till now, vscode-jest extension is not so stable and still has some bugs. So in my case, I decided to disable it for the meanwhile.
Upvotes: 16