mochajs是一款流行的nodejs测试工具。git地址:https://github.com/mochajs/mocha。
npm install mocha --save-dev安装。
在工具目录下创建test目录。
在test目录下创建test.js(mocha会自动寻找test目录下所有js文件),编写测试代码:
var assert = require('assert');
describe('calculate', () => {
it('plus', () => {
assert.ok( 1 + 1 === 2);
})
})
这里使用的是assert作判断,当然你也可以使用should或者其他的工具。