开始
优质
小牛编辑
130浏览
2023-12-01
$ npm install mocha
$ mkdir test
$ $EDITOR test/test.js # or open with your favorite editor
在编辑器中输入:
var assert = require('assert');
describe('Array', function() {
describe('#indexOf()', function() {
it('should return -1 when the value is not present', function() {
assert.equal([1,2,3].indexOf(4), -1);
});
});
});
然后在终端中运行:
$ ./node_modules/mocha/bin/mocha
Array
#indexOf()
✓ should return -1 when the value is not present
1 passing (9ms)
在的package.json中设置一个测试脚本:
"scripts": {
"test": "mocha"
}
然后运行:
$ npm test