Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vscode automatic type acquisition for jest

I have vscode 1.9 and I want to have intellisense for jest tests. The problem is that describe, it, expect etc are globally available in jest and you don't need to import them in your test files. So vscode will not show intellisense for them.

Is there any configuration for globals for automatic type acquisition?

like image 415
alisabzevari Avatar asked Feb 03 '17 12:02

alisabzevari


People also ask

How do I turn on auto suggestion in VS Code?

You can trigger IntelliSense in any editor window by typing Ctrl+Space or by typing a trigger character (such as the dot character (.) in JavaScript).

How do I enable IntelliSense in Visual Studio?

To access this options page, choose Tools > Options, and then choose Text Editor > C# > IntelliSense.


1 Answers

You have a few options in this case:

Add jest to your package.json:

"dependencies": {   "jest": "^18.1.0" } 

This only works if you are working JavaScript and do not have a tsconfig.json.


Install @types/jest

$ npm install -D @types/jest 

This should work for both JavaScript and TypeScript projects. However @types but may be disabled by a jsconfig.json/tsconfig.json: http://www.typescriptlang.org/docs/handbook/tsconfig-json.html


Create a jsconfig.json file in the root of your workspace to specifically include jest:

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

This will only work for JavaScript projects when automatic typings acquisition is enabled.

All of these should allow VSCode to pick up jest's typings without an import or require

like image 99
Matt Bierner Avatar answered Sep 16 '22 14:09

Matt Bierner