【发布时间】:2015-07-03 13:55:27
【问题描述】:
我正在尝试获取 MOCHA JS 测试中的代码覆盖率。我正在使用毯子,但我得到 0 % 的覆盖率 0 SLOC,为什么我不明白。 我的 package.json 是
{
"name": "basics",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha && mocha test --require blanket --reporter html-cov > coverage.html"
},
"author": "",
"license": "MIT",
"devDependencies": {
"chai": "~2.2.0",
"mocha": "~2.2.4",
"blanket": "~1.1.6",
},
"config": {
"blanket": {
"pattern": ["index.js"],
"data-cover-never": "node_modules"
}
}
}
而 index.js 是
exports.sanitize = function(word){
return word.toLowerCase().replace(/-/g, ' ');
}
exports.testToString = function(){
return word.toLowerCase().replace(/-/g, ' ');
}
test 文件夹下的 indexSpec.js 是
var chai = require('chai');
var expect = require('chai').expect;
var word = require('../index.js');
describe ('sanitize', function(){
it('String matching ', function(){
var inputWord = 'hello WORLD';
var outputWord = word.sanitize(inputWord);
expect(outputWord).to.equal('hello world');
expect(outputWord).to.not.equal('HELLO WORLD');
expect(outputWord).to.be.a('string');
expect(outputWord).not.to.be.a('number');
});
it('Checke hyphen ', function(){
var inputWord = 'hello-WORLD';
var outputWord = word.sanitize(inputWord);
expect(outputWord).to.equal('hello world');
});
} )
【问题讨论】:
-
我也遇到了同样的问题,你解决过这个问题吗?我的 package.json 脚本和配置看起来和你的一样。
-
我也遇到了这个问题。
-
这个问题在我安装了最新的节点 js 后得到了解决
标签: javascript node.js mocha.js chai blanket.js