Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code not recognizing Jest, underlining with Intellisense

I'm using VS Code in a Typescript project that uses Jest for testing. For some reason, VS Code thinks that the Jest globals are not available:

VS Code intellisense underlining Jest in red

I have the Jest typedefs installed in my dev dependencies.

"devDependencies": {
    // ...truncated
    "@types/jest": "^20",
    "jest": "^20.0.4",
    "ts-jest": "^20.0.7",
    "ts-node": "^5.0.0",
    "typescript": "~2.4.0"
}
like image 509
Steven Musumeche Avatar asked Jan 02 '23 14:01

Steven Musumeche


1 Answers

Correct answer here is that typescript requires type declarations for jest before jest global objects are visible for intellisense.

Add this triple-slash directive to beginning of your test file:

/// <reference types="jest" />
like image 72
Licensed Slacker Avatar answered Jan 05 '23 15:01

Licensed Slacker