我有一个模块,我希望使用伊斯坦布尔进行代码覆盖,但是当我使用箭头功能时,我无法使其正常工作. 我的模块compute.js 'use strict';exports.addition = (a, b) = { return a + b;}exports.multiplication = (a,
我的模块compute.js
'use strict'; exports.addition = (a, b) => { return a + b; } exports.multiplication = (a, b) => { return a * b; }
和我的单元测试代码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)) }) }) })
当我运行此命令
node_modules/.bin/istanbul cover node_modules/mocha/bin/_mocha test/test.js
我得到的保险摘要如下所示:
================== Coverage summary ======================= Statements : 100% (4/4) Branches : 100% (0/0) Functions : 100% (0/0) Lines : 100% (4/4)
在我的Function行中,如果我将compute.js更改为使用函数调用,我将获得0/0.
exports.addition = function(a, b) { return a + b; } exports.multiplication = function(a, b) { return a * b; }
现在,我得到了正确的代码覆盖率
================== 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"
我可以知道为什么箭头功能不起作用,我该如何修复它们?
这是当前伊斯坦布尔版本中的一个错误,我在他们的Github页面中创建了一个问题https://github.com/gotwarlost/istanbul/issues/486