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