提问者:小点点

找不到名称“describe”。您需要为测试运行程序安装类型定义吗?


当将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运行测试


共1个答案

匿名用户

我使用Visual Studio代码作为我的IDE和Angular项目,我必须注释掉/删除tsconfig.json文件中的类型,并在tsconfig.spec.json中的类型中添加“jest”。

{
  "compilerOptions": {
    // "types": []
  }
}
{
  "compilerOptions": {
    "types": ["jest", "node"]
  }
}