单元测试UI

cnpm install -g --save mocha   

cnpm install  -g --save chai  

cnpm install -g --save istanbul

const {should,expect,assert} = require('chai');
const {add,mul} = require('./math')
describe("#math",()=>{
describe('add',()=>{
it('shoule return 5 when 2+3',()=>{
expect(add(2,3),5);
});
it('shoule return 5 when 2+3',()=>{
expect(add(2,-3),-1);
})
})
describe('mul',()=>{
it('shoule return 5 when 2*3',()=>{
expect(add(2,3),6);
});
it('shoule return 5 when 2*3',()=>{
expect(add(2,-3),-6);
})
})
})

这里很重要
"scripts": {

"test": "mocha test/mocha.js",
"cover": "istanbul cover ./node_modules/mocha/bin/_mocha test/mocha.js"
},

猜你喜欢

转载自www.cnblogs.com/joer717/p/10573139.html