istanbul icon indicating copy to clipboard operation
istanbul copied to clipboard

"istanbul ignore next" over methods of an es6 class

Open ottes opened this issue 10 years ago • 45 comments

Following example says, that doSomething is not covered, but i guess it should be "ignored"

class Foo {
   /* istanbul ignore next */
  doSomething () {
    return 'something';
  }
}

if i move the ignore-comment into the method, the return is ignored, but the function is still uncovered

ottes avatar Sep 16 '15 07:09 ottes

+1 to this. Having issues ignoring an inquirer based function and callback which I plan to test at a later date after a refactor.

davemackintosh avatar Oct 05 '15 14:10 davemackintosh

Found a workaround (spaces before and after the comment seem to be necessary):

class Foo {
  bar /* istanbul ignore next */ () {
    return 'biu~';
  }
}

vilicvane avatar Oct 23 '15 07:10 vilicvane

+1

dcrockwell avatar Feb 09 '16 06:02 dcrockwell

If you're using babel and mocha, you can use the loose mode for ES6 classes:

{
  "presets": ["es2015"],
  "plugins": [
    ["transform-es2015-classes", {
      "loose": true
    }]
  ]
}

This will generate code like this:

/* istanbul ignore next */
MyClass.prototype.myMethod = function () { }

Which istanbul understands perfectly

EDIT: Otherwise babel would do sth like this:

  _createClass(MyClass, [{
    key: "myMethod",

    /* istanbul ignore next */
    value: function myMethod() {}
  }]);

saschagehlich avatar Mar 03 '16 14:03 saschagehlich

+1 for this

atian25 avatar Mar 13 '16 02:03 atian25

half way through 2016 now.. any update on this?

seanzer avatar Aug 09 '16 20:08 seanzer

+1

tesarm avatar Sep 08 '16 12:09 tesarm

This is still an issue, having to put the comment between descriptor and signature is a horrible looking hack I have to say.

davemackintosh avatar Oct 18 '16 13:10 davemackintosh

+1

BenDavidJamin avatar Oct 18 '16 22:10 BenDavidJamin

+1. Beginning of 2017, I am still waiting.

hirikarate avatar Feb 16 '17 14:02 hirikarate

ye, I have agree with this. I didn't use coverage before, but now that i am using react-boilerplate, I do find it valuable.

I also understand (from a Martin Fowler article) that we shouldn't be neurotic over getting 100% coverage.

However I find it cumbersome to have to go through the whole list of files and percentages, to see wether a lack of coverage comes from files where I expect it to come from, or wether it is a new place where I actually should improve the testing. That's why I want to have it at 100% all the time, so I can see at once if something is wrong or not. Now I find myself fighting istanbul to get coverage to 100% for places that are hard or unnecessary to test, which is a bit frustrating.

/* istanbul ignore function */ /* istanbul ignore file */ /* istanbul ignore start */ /* istanbul ignore end */

would be great to have!

devboell avatar Mar 13 '17 13:03 devboell

+1 for /* istanbul ignore file */

krasimir avatar Mar 14 '17 18:03 krasimir

class Foo {
  bar /* istanbul ignore next */ () {
    return 'biu~';
  }
}

This work-around doesn't work for this type of code:

.then(data => {
    },
    error /* istanbul ignore next */ => {
       // no matter what, cannot switch coverage off here
    });

vitaly-t avatar Jun 28 '17 15:06 vitaly-t

For es6 react app I just did this:

  const foo = /* istanbul ignore next */ () => {
      return bar;
  }

dcmwong avatar Oct 09 '17 16:10 dcmwong

Who's still waiting for this in 2018?

MatteoGabriele avatar Apr 12 '18 08:04 MatteoGabriele

The following works for my React class using the version of Istanbul that comes with Jest 22.4

/* istanbul ignore next */
componentWillReceiveProps(props) {
    // ...
}

designbyadrian avatar Apr 23 '18 10:04 designbyadrian

waiting for

/* istanbul ignore function */
/* istanbul ignore file */
/* istanbul ignore start */
/* istanbul ignore end */

greetings from Istanbul,.. May 2018

nxpatterns avatar May 18 '18 12:05 nxpatterns

/* istanbul ignore file */ working well for me.

Currently using nyc v11.9.0

jimmycann avatar Jun 08 '18 04:06 jimmycann

2019 +1

GitVitor avatar Jan 10 '19 15:01 GitVitor

+1 to

/* istanbul ignore function */

It would be amazing. Or just an /* istanbul ignore next */ that works. The workaround does not work for Vue SPC.

As a lot of time has already passed, what about /* constantinople ignore next */?

darioblanco avatar Jan 29 '19 14:01 darioblanco

As a lot of time has already passed, what about /* constantinople ignore next */?

Why they'd change it, I can't say.

thephilwells avatar Jan 29 '19 14:01 thephilwells

Hi! I've hit a similar issue... we are using Relay containers (ex. createPaginationContainer) and I am testing only the Component which this HOC wraps. Therefore I would like to ignore the HOC in the coverage.

Here is an example what doesn't work and what works:

This doesn't work: /* istanbul ignore next */ export default createPaginationContainer( myComponent, { query: graphql '...' }, getVariables: () => (), ...

This works: export default createPaginationContainer( myComponent, { query: /* istanbul ignore next */ graphql '...' }, getVariables: /* istanbul ignore next */ () => (), ...

The working example is not so nice to see and write... so my question is: Is there anyway to do it like in the first example? Or has the Istanbul team some plans to support such ignores?

Thank you

Bekaxp avatar Feb 06 '19 11:02 Bekaxp

Is this issue even being monitored? @gotwarlost +1

alefi87 avatar Feb 13 '19 10:02 alefi87

/* istanbul ignore start */ /* istanbul ignore end */

These two are really all that would be left from the op. They would alleviate the need for convenience the other two file and function commands though. They would be fantastic to have and likely would have garnered more usefulness overall, imho.

/* istanbul ignore file */ /* istanbul ignore function */

These two already exist and work from my testing with my typescript, istanbul, mocha, chia, sinon instance.

brycepelletier avatar Feb 19 '19 14:02 brycepelletier

/* istanbul ignore start / / istanbul ignore end */

These two are really all that would be left from the op. They would alleviate the need for convenience the other two file and function commands though. They would be fantastic to have and likely would have garnered more usefulness overall, imho.

/* istanbul ignore file / / istanbul ignore function */

These two already exist and work from my testing with my typescript, istanbul, mocha, chia, sinon instance.

@brycepelletier /* istanbul ignore function */ didn't work for me. what's your version ?

danielsss avatar Mar 05 '19 06:03 danielsss

...... 2020

raffaele-abramini avatar Jan 10 '20 15:01 raffaele-abramini

...... 2020

I don't think this repo is updated anymore. The last commit was in 2017.

fr0 avatar Jan 10 '20 15:01 fr0

It just became a tradition to come here once a year to check

MatteoGabriele avatar Jan 10 '20 15:01 MatteoGabriele

"karma-coverage-istanbul-reporter": "~2.0.1"

/* istanbul ignore next */ 
 private myFunction() {...}

works for me in an angular-cli 8 project...

EDIT: oh, sry! i just realized that karma-istanbul refers to istanbuljs :D

guntram avatar Jan 23 '20 17:01 guntram

+1 in 2020.

33percent avatar Feb 03 '20 10:02 33percent