mocha 学习
mocha
-
install npm i mocha --save-dev
-
demo
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); }); }); });
-
tips:
- 需要创建test文件夹,而且放在和package.json同级目录下面的
- 配置package.json的script的"test":"mocha"
- 运行 npm test
-
hooks
describe('hooks', function () {
before(function () {
// runs once before the first test in this block
});
after(function () {
// runs once after the last test in this block
});
beforeEach(function () {
// runs before each test in this block
});
afterEach(function () {
// runs after each test in this block
});
// test cases
});
- reference link