Bug: Code Coverage Report
- [x] bug report -> please search issues before submitting
- [ ] feature request
Versions.
$ ng --version @angular/cli: 1.0.0-rc.2 node: 6.9.5 os: win32 x64 @angular/common: 4.0.0-rc.5 @angular/compiler: 4.0.0-rc.5 @angular/core: 4.0.0-rc.5 @angular/forms: 4.0.0-rc.5 @angular/http: 4.0.0-rc.5 @angular/platform-browser: 4.0.0-rc.5 @angular/platform-browser-dynamic: 4.0.0-rc.5 @angular/router: 4.0.0-rc.5 @angular/cli: 1.0.0-rc.2 @angular/compiler-cli: 4.0.0-rc.5
Repro steps.
I have made a sample project, to reproduce this weird behaviour.
Please take a look at: https://github.com/Loster102/angular-coverage-sample
When I run 'ng test -cc true', there is a successful testrun.
But when I look at the coverage report, the branch coverage is really strange.
It says, that the constructor is not fully covered.
Desired functionality.
I would have expected that even the constructor is fully covered.
Mention any other details that might be useful.
In my real world application, there are some further strange behaviours, exactly like the one above. I try to reproduce these in the sample project. In this application, I'm using [email protected] and @angular/[email protected].
I resolved it by running the unit test environment in full privileged mode
Hey guys ! So de we know how Angular 5 fixed this issue... ? :-P
Yeah has to do with the annotations now being parsed as typescript transformations instead. I'll try to find the article but it now doesn't put the same ternary operators which were found in the code coverage for constructors and input/outputs
On Tue, Feb 20, 2018, 12:42 PM otroboe [email protected] wrote:
Hey guys ! So de we know how Angular 5 fixed this issue... ? :-P
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/5526#issuecomment-367058155, or mute the thread https://github.com/notifications/unsubscribe-auth/AMPLtSEh5oxmc3taE5JVdrBecojU8jBsks5tWwQdgaJpZM4Mi9tY .
@laxu have you fix this when using jest????
For me with Jest 22.3.0, I just added this property in my jest.json config file:
{
...
"mapCoverage": true
}
@vigohe I experience the same issue with Jest.
@otroboe the option mapCoverage doesn't help. It was also removed in Jest 22.4
@filipesilva can you tell us exactly what was the fix in Angular 5 ?
I don't believe that jest is covered by the cli. In which case this doesn't belong here but on stack overflow.
On Sat, Mar 3, 2018, 8:33 PM Ahn [email protected] wrote:
@otroboe https://github.com/otroboe Angular 5 fixed the issue but only when testing with karma + jasmine, with Jest I also experience the same issue. @filipesilva https://github.com/filipesilva can you tell us exactly what was the fix in Angular 5 ?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/5526#issuecomment-370194403, or mute the thread https://github.com/notifications/unsubscribe-auth/AMPLtUKPtuq-KCUr64POpqXwqLIUEJjbks5ta0R1gaJpZM4Mi9tY .
+1
It seems most of the issues are solved nevertheless we are still experiencing same issue like @brunolm mentioned

We are experiencing this in our project with constructors and decorators. Running angular 5.2.8, angular-cli 1.7.3, jasmine 3.1.0 running with karma.
I resolve the problem by targetting es6 in tsconfig.spec.json
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/spec",
"baseUrl": "./",
"module": "commonjs",
"target": "es6",
"types": ["jasmine", "node"]
},
"files": ["test.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
Just make sure that you have sourcemaps turned on for your tests and coverage will work fine.
@macbem Not the case for me, I experience this problem with and without sm flag.
Thanks for the suggestions @macbem and @rousseaufiliong. I previously tried those suggestions along with the other suggestions in this thread like adding /* istanbul ignore next */ and I tried again today for good measure but still find coverage is low for branches because of constructors and decorators. Hopeful an update solves this for our project
Is a fix on the way?
I experience this problem with having source maps turned off for testing.
@filipesilva with version 1.7.4 the problem continues :(
We're also still seeing the same problem, Angular 5.2.6, Jest 22.4.3 and Jest Angular Preset 5.2.2. For whatever reason, it's not all the time, but there are issues where some of the params in a constructor will be uncovered. It doesn't seem to make a lot of sense, because it's not consistent.
Also seeing this behaviour as described by @mcblum
indeed, after adding --sourcemaps=false coverage started giving wrong numbers (cli 1.7.4, target es5). When you remove it, coverage is ok.
