Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get 100% of karma branch code coverage in typescript angular app?

I write my angular application with karma and jasmin unit tests. I got code in typescript:

module app {
  ...
}

which generates to javascript like:

var app;
(function (app) {
...
})(app || (app = {}));

Now when I run karma-coverage it shows me that one branch is skipped and it's || (app = {})); this one. It happens when I test more files which got app module.

How can I test it in jasmine, to get 100% branch coverage?

like image 663
Marcin Avatar asked Nov 10 '22 08:11

Marcin


1 Answers

If you have a build process using gulp or grunt, after your typescript gets compiled to javascript, you can tell Istanbul (what karma-coverage uses to generate code coverage) to ignore certain lines (like those pesky typescript-generated lines).

You can tell Istanbul to ignore a line by using the /* istanbul ignore next */ comment

(function (app) {
...
})(/* istanbul ignore next */app || (app = {}));

Here's a post explaining how to do just that using gulp.

https://stackoverflow.com/a/33024388/1633757

like image 151
TwitchBronBron Avatar answered Nov 15 '22 05:11

TwitchBronBron