istanbul
istanbul copied to clipboard
Istanbul function coverage for arrow function?
I have a module that I would like to have code coverage using Istanbul
, but I cant get it working when I use arrow function.
my module compute.js
'use strict';
exports.addition = (a, b) => {
return a + b;
}
exports.multiplication = (a, b) => {
return a * b;
}
and my unit test code test.js
describe('Compute', function() {
describe('addition()', function() {
it('should add', function() {
assert.equal(5, compute.addition(2, 3))
assert.equal(15, compute.addition(2, 13))
})
})
describe('multiplication()', function() {
it('should multiply', function() {
assert.equal(6, compute.multiplication(2, 3))
assert.equal(26, compute.multiplication(2, 13))
})
})
})
When i run this command
node_modules/.bin/istanbul cover node_modules/mocha/bin/_mocha test/test.js
I get my coverage summary shown below:
================== Coverage summary =======================
Statements : 100% (4/4)
Branches : 100% (0/0)
Functions : 100% (0/0)
Lines : 100% (4/4)
In my Function row, i am getting 0/0, if i change my compute.js
to use function call.
exports.addition = function(a, b) {
return a + b;
}
exports.multiplication = function(a, b) {
return a * b;
}
now, i am getting the correct code coverage
================== Coverage summary =======================
Statements : 100% (4/4)
Branches : 100% (0/0)
Functions : 100% (2/2)
Lines : 100% (4/4)
package.json
"istanbul": "^0.4.0",
"mocha": "^2.3.4"
May i know why the arrow function is not working and how can I fix them?
Looks like istanbul is not counting arrow functions as "functions". This should be easy to fix but I'm in he middle of a refactor so I can only get to it later.
Thanks for reporting this issue.
@sweetim I had same error. But in my case root of the problem was damn stupid. I just forgot to remove describe.only from one of my tests! =))) I thought it may help you.
The issue still exists with [email protected]
. Any update?
Istanbul's inability to cover arrow functions is causing me to do some frustrating refactoring. Do we have any updates on this?
You could use nyc
package
https://www.npmjs.com/package/nyc
this problem has been resolved with that package! ;)
@sweetim it should be a native function from Istanbul instead using another package.
We seem to be having this same problem with Jest here
Any updates?
Updates on this issue?
Still active
As stated in the readme, this version of Istanbul has been deprecated, 5 years ago already. Use https://github.com/istanbuljs/nyc @gotwarlost why don't you put this repo into read-only mode?
As stated in the readme, this version of Istanbul has been deprecated, 5 years ago already. Use https://github.com/istanbuljs/nyc @gotwarlost why don't you put this repo into read-only mode?
Sorry!