- npm安装模组
npm install --save mocha
- 修改package.json
"scripts": {
"start": "node ./bin/www",
"test" : "mocha"
},
- 根目录下新建test文件夹
mkdir test
- 编写待测试脚本wordGainScore.js
function wordGainsScore(str) {
.....
module.exports = wordGainsScoreHtml;
- test文件夹下编写测试脚本wordGainScore.test.js
var assert = require('assert');
var wordGainScore = require('../js/wordGainScore');
describe('Q1:wordGainScore',function(){
it('should return 0 when string is bcd',function(){
assert.equal(0,wordGainScore('bcd'));
});
it('should return 15 when string is AeIoU',function(){
assert.equal(15,wordGainScore('AeIoU'));
});
});
- mocha测试
npm test