Code coverage report showing if path not taken and else path not taken even though there are no if and else statements. This affecting the branch coverage.

Angular version we are using is : 5.1.3
"@angular/cli": "1.6.0",
"@angular/compiler-cli": "5.1.3",
This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?
You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.
also just seeing this error now after upgrading to latest Angular and Angluar CLI. will try to create a sample repo if OP hasn't yet.
I fixed this problem for my project.
I upgraded my angular specific dependencies to the latest.
And taking out --sm=false flag that I had to run test did the trick.
Once I took that flag out and ran test like so ng test --single-run --browsers ChromeHeadless --watch=false --cc The test coverage calculation went back correctly.
my project's dependencies versions FYI
"dependencies": {
"@angular/animations": "^5.2.0",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"core-js": "^2.4.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "1.6.8",
"@angular/compiler-cli": "^5.2.0",
"@angular/language-service": "^5.2.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
}
Hi all,
We cross checked dependencies in package.json, there is a some issue with Jasmin what we used. Now working as expected.
Closing as it seems to be sorted.
@Tataraovoleti which version of Jasmine you changed it to make it work?
@filipesilva please reopen, this is not sorted.
@filipesilva if you want to reproduce it, just create a new ng project and run ng test --code-coverage
Angular CLI: 6.1.0
Node: 9.11.1
OS: darwin x64
Angular: 6.1.0
... animations, cli, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.7.0
@angular-devkit/build-angular 0.7.0
@angular-devkit/build-optimizer 0.7.0
@angular-devkit/build-webpack 0.7.0
@angular-devkit/core 0.7.0
@angular-devkit/schematics 0.7.0
@ngtools/webpack 6.1.0
@schematics/angular 0.7.0
@schematics/update 0.7.0
rxjs 6.2.2
typescript 2.7.2
webpack 4.9.2
lol, worked with source map flag. 100% of branches are now covered.
For those who are also not getting good code coverage
just run:
ng test --source-map --code-coverage
As @stewwan mentioned I found that setting the "sourceMap": true in angular.json fixed the issue for me. Thanks man!
Oh good to know, I鈥檒l do that too 馃檪
@stewwan I am even getting the same issue, i found my sourceMap:False in Angular.json.
Do i need to make any changes as True for that so that my issue can be sloved?

This is the issue which i have we are using angular 6
@stewwan 's suggestion worked.
ng test --source-map --code-coverage
@stewwan Maybe check if that's not a false positive. If I run it with --source-map the branch coverage is 100% but the actual amount of branches is 0/0. So there is a little bit of sleight of hand going on. When I put it to --source-map=false then it gives the right values but the report is a bit mixed up.
@filipesilva I'm still experiencing this issue.
I'm seeing the same issue @marthinus-engelbrecht is seeing when using angular-cli 8.0.0. When running tests on a Mac, setting --sourceMap true causes my coverage to pass when it should not (shows 0/0 branches) and setting it to false detects the lines but makes debugging difficult. On Linux, coverage reports are accurate regardless of the sourceMap flag value.
We would like to have the source maps for debugging purposes but also need accurate coverage reports.
Is there anything I'm missing that would cause reports to be different based on the platform they're running on?
update: never seen it again since I moved to nx mono repositories which uses jest as test runner. cc @marthinus-engelbrecht
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
lol, worked with source map flag. 100% of branches are now covered.
For those who are also not getting good code coverage
just run:
ng test --source-map --code-coverage