问题描述
我有 vscode 1.9 并且我想有用于玩笑测试的智能感知.问题是 describe
、it
、expect
等在 jest 中是全局可用的,你不需要 import
它们在您的测试文件中.所以 vscode 不会为他们显示智能感知.
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?
推荐答案
在这种情况下,您有几个选择:
You have a few options in this case:
将 jest
添加到您的 package.json
:
"dependencies": {
"jest": "^18.1.0"
}
这仅在您使用 JavaScript 并且没有 tsconfig.json
时才有效.
This only works if you are working JavaScript and do not have a tsconfig.json
.
安装@types/jest
$ npm install -D @types/jest
这应该适用于 JavaScript 和 TypeScript 项目.但是 @types
但可能被 jsconfig.json
/tsconfig.json
禁用:http://www.typescriptlang.org/docs/handbook/tsconfig-json.html
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
在工作区的根目录中创建一个 jsconfig.json
文件以专门包含 jest:
Create a jsconfig.json
file in the root of your workspace to specifically include jest:
{
"typeAcquisition": {
"include": [
"jest"
]
}
}
这仅适用于启用自动类型获取的 JavaScript 项目.
This will only work for JavaScript projects when automatic typings acquisition is enabled.
所有这些都应该允许 VSCode 在没有 import
或 require
All of these should allow VSCode to pick up jest's typings without an import
or require
这篇关于用于开玩笑的 vscode 自动类型获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!