《Mocha 单元测试入门》
1. 介绍
- 官方文档:https://mochajs.org/
- GitHub:https://github.com/mochajs/mocha
- should.js:https://github.com/shouldjs/should.js
2. 使用 should.js 断言示例
var should = require('should');
var user = {
name: 'tj',
pets: ['tobi', 'loki', 'jane', 'bandit']
};
user.should.have.property('name', 'tj');
user.should.have.property('pets').with.lengthOf(4);
// 若对象由 Object.create(null) 创建,没有 `.should` getter,需要改为:
should(user).have.property('name', 'tj');
// 对 null / undefined 的断言
should(null).not.be.ok();
someAsyncTask(foo, function (err, result) {
should.not.exist(err);
should.exist(result);
result.bar.should.equal(foo);
});
3. 常用断言库
- should.js https://github.com/shouldjs/should.js
- chai https://www.chaijs.com/
阅读 —
·
全站 —