assert

模块 assert

断言测试模块,如果测试值为假,则报错,报错行为可设定继续运行或者错误抛出。

引用方法:

1
var assert = require('assert');

静态函数

Function

测试数值为真,为假则断言失败

1
assert.Function(actual,msg);

调用参数:

ok

测试数值为真,为假则断言失败

1
assert.ok(actual,msg);

调用参数:

notOk

测试数值为假,为真则断言失败

1
assert.notOk(actual,msg);

调用参数:

equal

测试数值等于预期值,不相等则断言失败

1
assert.equal(actual,expected,msg);

调用参数:

notEqual

测试数值不等于预期值,相等则断言失败

1
assert.notEqual(actual,expected,msg);

调用参数:

strictEqual

测试数值严格等于预期值,不相等则断言失败

1
assert.strictEqual(actual,expected,msg);

调用参数:

notStrictEqual

测试数值不严格等于预期值,相等则断言失败

1
assert.notStrictEqual(actual,expected,msg);

调用参数:

deepEqual

测试数值深度等于预期值,不相等则断言失败

1
assert.deepEqual(actual,expected,msg);

调用参数:

notDeepEqual

测试数值不深度等于预期值,相等则断言失败

1
assert.notDeepEqual(actual,expected,msg);

调用参数:

closeTo

测试数值近似等于预期值,否则断言失败

1
assert.closeTo(actual,expected,delta,msg);

调用参数:

notCloseTo

测试数值不近似等于预期值,否则断言失败

1
assert.notCloseTo(actual,expected,delta,msg);

调用参数:

lessThan

测试数值小于预期值,大于或等于则断言失败

1
assert.lessThan(actual,expected,msg);

调用参数:

notLessThan

测试数值不小于预期值,小于则断言失败

1
assert.notLessThan(actual,expected,msg);

调用参数:

greaterThan

测试数值大于预期值,小于或等于则断言失败

1
assert.greaterThan(actual,expected,msg);

调用参数:

notGreaterThan

测试数值不大于预期值,大于则断言失败

1
assert.notGreaterThan(actual,expected,msg);

调用参数:

exist

测试变量存在,为假则断言失败

1
assert.exist(actual,msg);

调用参数:

notExist

测试变量不存在,为真则断言失败

1
assert.notExist(actual,msg);

调用参数:

isTrue

测试数值为布尔值真,否则断言失败

1
assert.isTrue(actual,msg);

调用参数:

isNotTrue

测试数值不为布尔值真,否则断言失败

1
assert.isNotTrue(actual,msg);

调用参数:

isFalse

测试数值为布尔值假,否则断言失败

1
assert.isFalse(actual,msg);

调用参数:

isNotFalse

测试数值不为布尔值假,否则断言失败

1
assert.isNotFalse(actual,msg);

调用参数:

isNull

测试数值为 Null,否则断言失败

1
assert.isNull(actual,msg);

调用参数:

isNotNull

测试数值不为 Null,否则断言失败

1
assert.isNotNull(actual,msg);

调用参数:

isUndefined

测试数值为 undefined,否则断言失败

1
assert.isUndefined(actual,msg);

调用参数:

isDefined

测试数值不为 undefined,否则断言失败

1
assert.isDefined(actual,msg);

调用参数:

isFunction

测试数值为函数,否则断言失败

1
assert.isFunction(actual,msg);

调用参数:

isNotFunction

测试数值不为函数,否则断言失败

1
assert.isNotFunction(actual,msg);

调用参数:

isObject

测试数值为对象,否则断言失败

1
assert.isObject(actual,msg);

调用参数:

isNotObject

测试数值不为对象,否则断言失败

1
assert.isNotObject(actual,msg);

调用参数:

isArray

测试数值为数组,否则断言失败

1
assert.isArray(actual,msg);

调用参数:

isNotArray

测试数值不为数组,否则断言失败

1
assert.isNotArray(actual,msg);

调用参数:

isString

测试数值为字符串,否则断言失败

1
assert.isString(actual,msg);

调用参数:

isNotString

测试数值不为字符串,否则断言失败

1
assert.isNotString(actual,msg);

调用参数:

isNumber

测试数值为数字,否则断言失败

1
assert.isNumber(actual,msg);

调用参数:

isNotNumber

测试数值不为数字,否则断言失败

1
assert.isNotNumber(actual,msg);

调用参数:

isBoolean

测试数值为布尔,否则断言失败

1
assert.isBoolean(actual,msg);

调用参数:

isNotBoolean

测试数值不为布尔,否则断言失败

1
assert.isNotBoolean(actual,msg);

调用参数:

typeOf

测试数值为给定类型,否则断言失败

1
assert.typeOf(actual,type,msg);

调用参数:

notTypeOf

测试数值不为给定类型,否则断言失败

1
assert.notTypeOf(actual,type,msg);

调用参数:

property

测试对象中包含指定属性,否则断言失败

1
assert.property(object,prop,msg);

调用参数:

notProperty

测试对象中不包含指定属性,否则断言失败

1
assert.notProperty(object,prop,msg);

调用参数:

deepProperty

深度测试对象中包含指定属性,否则断言失败

1
assert.deepProperty(object,prop,msg);

调用参数:

notDeepProperty

深度测试对象中不包含指定属性,否则断言失败

1
assert.notDeepProperty(object,prop,msg);

调用参数:

propertyVal

测试对象中指定属性的值为给定值,否则断言失败

1
assert.propertyVal(object,prop,value,msg);

调用参数:

propertyNotVal

测试对象中指定属性的值不为给定值,否则断言失败

1
assert.propertyNotVal(object,prop,value,msg);

调用参数:

deepPropertyVal

深度测试对象中指定属性的值为给定值,否则断言失败

1
assert.deepPropertyVal(object,prop,value,msg);

调用参数:

deepPropertyNotVal

深度测试对象中指定属性的值不为给定值,否则断言失败

1
assert.deepPropertyNotVal(object,prop,value,msg);

调用参数:

throws

测试给定的代码会抛出错误,未抛出则断言失败

1
assert.throws(Function block,msg);

调用参数:

doesNotThrow

测试给定的代码不会抛出错误,抛出则断言失败

1
assert.doesNotThrow(Function block,msg);

调用参数:

ifError

如果参数为真,则抛出

1
assert.ifError(object);

调用参数: