Pregunta

I'm creating some unit tests with Jasmine and the test runner I'm using is Karma. I'm also checking the code coverage of these test specs with the karma-coverage plugin.

I was wondering if there's any way of excluding certain functions from the code coverage itself and also from the Karma report (Istanbul actually). I'm thinking that if the first one is solved then so is the second.

Pretty sure there's no obvious way of doing this, as I've looked in Istanbul as well (karma-coverage uses it) but maybe some of you run into this before.

¿Fue útil?

Solución

It appears that the guy behind Istanbul has added support for ignoring specific sections of code from coverage analysis. Really useful!

More here: https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md

Otros consejos

Use below lines of code to ignore code for coverage.

/* istanbul ignore if */      ---skips the "if thing" in the source code
/* istanbul ignore else */    ---skips the "else thing" in the source code
/* istanbul ignore next */    ---skips the "next thing" in the source code

Sometimes you want to ignore testing of the framework itself that you are currently using. That is typically the main reason for my need of this kind of functionality.

Is that function actually being used? If not, you can comment it or remove it completely. But if there's a reason for this function, then let the code coverage results point you out that this function is not tested!

Otherwise, could you put this particular function in it's own file and exclude this file from istanbul?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top