使用 Jest 我得到:找不到“茉莉花"的类型定义文件 [英] Using Jest I get: Cannot find type definition file for 'jasmine'
问题描述
我正在使用 Angular 7 和 Jest.当我用 --codecoverage
运行 jest 时,我所有的测试都通过了,但没有覆盖构造函数中的许多分支(类似于:未涵盖构造函数上的分支).
I am using Angular 7 and Jest. When I was running jest with --codecoverage
, all my tests passed but many branches in the constructor were not covered
(similar to: Branches on constructor not covered).
我花了很多时间到处检查如何解决它,似乎我不得不将 jest-preset-angular
升级到第 7 版.在我这样做之后,我所有的测试套件都失败了运行以下消息:
I spent quite a lot of time checking everywhere how to solve it and it seemed I had to upgrade jest-preset-angular
to version 7. After I did it, all my test suites fail to run with the following message:
src/app/whatever.component.spec.ts
● Test suite failed to run
TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
error TS2688: Cannot find type definition file for 'jasmine'.
我一直环顾四周,并尝试应用我找到的解决方案(例如 找不到 'jasmine' 的类型定义文件,错误 TS2688 中的错误:找不到 'jest' 的类型定义文件,...) 但没有工作.
I've been looking around and I tried to apply the solutions I found (such as Cannot find type definition file for 'jasmine', ERROR in error TS2688: Cannot find type definition file for 'jest', ...) but none worked.
我在这里复制了我在 package.json 中的一些依赖项:
I copy here some of the dependencies I have in package.json:
"jest": "^24.1.0",
"jest-junit": "^6.3.0",
"jest-preset-angular": "^7.0.1",
"ts-node": "~7.0.1",
"tslint": "~5.9.1",
"typescript": "3.2.4"
我之前的版本是:
"jest-preset-angular": "^6.0.2",
更新:我使用 Angular 6 和 Jasmine 开始了我的项目,然后将其更新为 Angular 7 和 Jest.我不知道这是不是重要信息.
Update: I started my project with Angular 6 and Jasmine and I updated it to Angular 7 and Jest. I don't know if this is an important information.
推荐答案
到 compilerOptions 下的 types 字段中的 tsconfig.spec.json 并删除 jasmine 并添加 jest
Go to tsconfig.spec.json in the types field under the compilerOptions and remove jasmine and add jest
"compilerOptions": {
"module": "commonjs",
"outDir": "./out-tsc/spec",
"types": ["jest", "node"]
}
这篇关于使用 Jest 我得到:找不到“茉莉花"的类型定义文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!