I am trying to get code coverage in the MOCHA JS test. I use a blanket, but I get 0% coverage 0 SLOC, why I do not understand. my 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" } } }
and index.js
exports.sanitize = function(word){ return word.toLowerCase().replace(/-/g, ' '); } exports.testToString = function(){ return word.toLowerCase().replace(/-/g, ' '); }
and indexSpec.js located in the test folder,
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'); }); } )
user993158
source share