Using Jest I get: Cannot find type definition file for 'jasmine'

后端 未结 3 1107
自闭症患者
自闭症患者 2021-02-08 22:44

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: B

3条回答
  •  猫巷女王i
    2021-02-08 23:07

    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:

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

    • Remove all Karma related stuff that was still there:

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

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

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

    • Updated package.json with "jest-preset-angular": "^7.0.1

    • 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!

提交回复
热议问题