You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var assert = require('assert');
describe('Array', function(){
beforeEach(function(){
this.ary = [1,2,3];
});
describe('#indexOf()', function(){
it('should return index when the value is present', function(){
var zero = 0, two = 2;
assert(this.ary.indexOf(zero) === two);
});
it('should return -1 when the value is not present', function(){
var minusOne = -1, two = 2;
assert.ok(this.ary.indexOf(two) === minusOne, 'THIS IS AN ASSERTION MESSAGE');
});
});
});
describe('various types', function(){
function Person(name, age) {
this.name = name;
this.age = age;
}
beforeEach(function(){
this.types = [
'string', 98.6, true, false, null, undefined,
['nested', 'array'],
{object: true},
NaN, Infinity,
/^not/,
new Person('alice', 3)
];
});
it('demo', function(){
var index = this.types.length -1,
bob = new Person('bob', 5);
assert(this.types[index].name === bob.name);
});
});
在写node的单元测试的时候我们常用的断言库有
Power Assert in JavaScript
Provides descriptive assertion messages through standard assert interface.
No API is the best API.
https://github.com/power-assert-js/power-assert
和常用的断言库相比,它的优点是
HOW TO USE
使用
babel-plugin-espower
插件安装
编辑
.babelrc
文件mocha 运行时通过
babel-register
编译文件The text was updated successfully, but these errors were encountered: