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

I am writing my angular application using unit tests of karma and jasmin. I got the code in typescript:

module app { ... } 

which generates javascript for example:

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

Now, when I start karma coverage, it shows me that one branch is missing and it || (app = {})); this. This happens when I test more files that the application module received.

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

+5
source share
2 answers

If you have a build process using gulp or grunts, after your typescript is compiled into JavaScript, you can say Istanbul (that karma coverage is used to create code coverage) to ignore certain lines (like those annoying typescript-generated lines) .

You can say that Istanbul ignores the line using the comment /* istanbul ignore next */

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

Here is a post explaining how to do this with gulp.

fooobar.com/questions/249137 / ...

+1
source

The remap-istanbul package should be able to convert Istanbul coverage report to source typescript when compiling with source maps.

You can take a look at Code Coverage for Typescript

0
source

All Articles