#486·istanbul

Istanbul function coverage for arrow function?

Author: sweetimCreated Nov 18, 2015Updated Oct 27, 2022
Labelsbugv1

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?