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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With