Marcin
Marcin

Reputation: 490

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?

Upvotes: 5

Views: 7653

Answers (2)

TwitchBronBron
TwitchBronBron

Reputation: 3186

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

Upvotes: 1

Jesper Rønn-Jensen
Jesper Rønn-Jensen

Reputation: 111616

The remap-istanbul package should be able to convert Istanbul coverage report to original typescript when you compile with sourcemaps.

You may have a look at Code Coverage for Typescript

Upvotes: 0

Related Questions