使用Jest我得到:找不到'jasmine'的类型定义文件 [英] Using Jest I get: Cannot find type definition file for 'jasmine'

查看:1237
本文介绍了使用Jest我得到:找不到'jasmine'的类型定义文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Angular 7和Jest.当我用--codecoverage开玩笑时,我所有的测试都通过了,但是构造函数中的许多分支都没有涉及 (类似于:未涵盖构造函数的分支).

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'.

我一直在环顾四周,我尝试应用发现的解决方案(例如,...),但没有任何作用.

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",

我不知道我可以提供哪些其他信息.如果有什么遗漏,如果您能在拒绝投票之前(实际上是代替)告诉我,我将不胜感激.

I don't know which additional information I can provide. If there is something missing I'd appreciate if you could tell me that before (actually: instead of) down voting...

更新:我从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.

谢谢!

推荐答案

我终于解决了我的问题.该解决方案基于@Emmy Omega的回答(这就是为什么我给予他赏金的原因)和@Akshay Rana的评论,但还需要做更多的事情.我的tsconfig.spec.json文件中确实有jasmine,但是用json更改(我已经尝试过)并不能解决问题.为了使其正常工作,我按照以下步骤操作:

I finally solved my problem. The solution is based on @Emmy Omega’s answer (that’s why I give him the bounty) and @Akshay Rana’s comment, but had to do some more things. I had jasmine indeed in my tsconfig.spec.json file, but changing it with json (I had already tried it) didn’t fix the problem. To make it work I followed the following steps:

更新npm (我有一个旧版本,安装软件包时遇到了一些问题.

• Update npm (I had an old version and I had some problems installing packages).

删除所有与Karma相关的内容仍然存在:

npm remove karma karma-chrome-launcher karma-coverage-istanbul-reporter karma-jasmine karma-jasmine-html-reporter

•我仍然有 test.ts文件,然后将其删除(不知道它来自何处).我还将其从tsconfig.app.jsontsconfig.spec.json中删除.

• I still had this test.ts file around and I deleted it (I don’t know where it came from). I also remove it from tsconfig.app.json and tsconfig.spec.json.

•在tsconfig.spec.json中,我用jest更改了jasmine的一次出现(如建议).

• In tsconfig.spec.json I changed one occurrence of jasmine with jest (as suggested).

•用"jest-preset-angular": "^7.0.1

•删除node_modules文件夹中的所有软件包,然后使用npm i重新安装所有软件包.

• Delete all packages in node_modules folder and reinstall them all again with npm i.

我不完全知道这些步骤中的哪一个有所作为,但最终奏效了!

I don’t know exactly which of these steps made the difference but it finally worked!

这篇关于使用Jest我得到:找不到'jasmine'的类型定义文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆