将 TypeScript 与 Jest 结合使用时,我的规范会失败并显示如下错误消息:
test/unit/some.spec.ts:1:1 - error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.
test/unit/some.spec.ts:2:3 - error TS2582: Cannot find name 'it'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.
test/unit/some.spec.ts:3:7 - error TS2304: Cannot find name 'expect'.
test/unit/some.spec.ts:7:1 - error TS2582: Cannot find name 'test'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.
类型已经安装。
我使用:
"@types/jest": "^23.3.12",
"jest": "^23.6.0",
"ts-jest": "^23.10.5",
"typescript": "^3.1.6"
我使用 jest --forceExit --coverage --verbose
运行测试
最佳答案
我在我的 Angular 项目和我的 IDE 中使用 Visual Studio Code,我不得不注释掉/删除文件 tsconfig.json 中的类型并在 中的类型中添加“jest” em>tsconfig.spec.json.
文件 tsconfig.json
{
"compilerOptions": {
// "types": []
}
}
文件 tsconfig.spec.json
{
"compilerOptions": {
"types": ["jest", "node"]
}
}
关于typescript - 找不到名称 'describe'。您需要为测试运行器安装类型定义吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54139158/