skipping lines in test coverage

1,634 views
Skip to first unread message

rok.g...@gmail.com

unread,
Sep 19, 2013, 3:57:12 PM9/19/13
to karma...@googlegroups.com
is there a way to tell karma-coverage to skip certain lines from coverage report?
i guess this should be somewhere documented in istanbul but i'm not able to find it.

Michael Bielski

unread,
Sep 20, 2013, 10:45:36 AM9/20/13
to karma...@googlegroups.com, rok.g...@gmail.com
I'm not sure I understand why you would want to skip lines in a coverage report. Could you elaborate?

Rok Garbas

unread,
Sep 20, 2013, 4:00:18 PM9/20/13
to Michael Bielski, karma...@googlegroups.com
Quoting Michael Bielski (2013-09-20 16:45:36)
> I'm not sure I understand why you would want to skip lines in a coverage
> report. Could you elaborate?

yeah ... maybe it would be nice to do this in the first email.

in other languages its quite common to skip certain lines of code which you
dont want to test (for whatever reason) in order to get

in my case reason is that you cannot really mock window.* stuff. therefore you
have to resort to something like ...
https://github.com/plone/mockup/blob/master/js/router.js#L94

and then mock it in test
https://github.com/plone/mockup/blob/master/tests/router-test.js#L51

what happens is that you cannot test those two lines from first link and
coverage looks like
https://coveralls.io/files/55682215#L94


did i explain it good enough? is there other way i could get around this
problem with some other pattern of testing.

tnx in advance.

--
Rok Garbas - http://www.garbas.si

Michael Bielski

unread,
Sep 23, 2013, 10:38:13 AM9/23/13
to karma...@googlegroups.com, Michael Bielski, rok.g...@gmail.com
You can mock pretty much anything with window.* in Jasmine. I think this thread might help you: https://groups.google.com/forum/?fromgroups#!topic/jasmine-js/1qjP-nDqAgU

I've mocked both local and session storage, as well as window.confirm, so I see no reason why the solution in that thread wouldn't work.

Vojta Jína

unread,
Sep 23, 2013, 3:03:49 PM9/23/13
to karma...@googlegroups.com
Hi Rok,

I don't think Istanbul supports this and honestly I don't see any reason why it should.

If you use Dependency Injection pattern - passing all the deps in constructor, you can wrap the window.location API into an object that is passed as a dependency into the Router constructor and during the test you pass in a mock. Then, you can call that method and you will get the coverage you want ;-)

Btw, you should use spyOn(Router, '_change_location'), that will automatically remove the spy (monkey patching the method) after each spec.

That said, I don't think that having 100% coverage gives you that much (most of the time people end up writing useless tests just to keep the high coverage ;-)).

All the best,
V.


On Mon, Sep 23, 2013 at 4:38 PM, Michael Bielski <michael...@yahoo.com> wrote:
You can mock pretty much anything with window.* in Jasmine. I think this thread might help you: https://groups.google.com/forum/?fromgroups#!topic/jasmine-js/1qjP-nDqAgU

I've mocked both local and session storage, as well as window.confirm, so I see no reason why the solution in that thread wouldn't work.

--
You received this message because you are subscribed to the Google Groups "karma-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to karma-users...@googlegroups.com.
To post to this group, send email to karma...@googlegroups.com.
Visit this group at http://groups.google.com/group/karma-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages