断言测试模块,如果测试值为假,则报错,报错行为可设定继续运行或者错误抛出
引用方法:
var assert = require('assert');
或者通过 test 模块引用:
var test = require('test');
var assert = test.assert;
或者通过 test.setup 配置:
require("test").setup();
| Type | Method and Description |
|---|---|
| void | Function(Value actual,String msg)测试数值为真,为假则断言失败 |
| void | ok(Value actual,String msg)测试数值为真,为假则断言失败 |
| void | notOk(Value actual,String msg)测试数值为假,为真则断言失败 |
| void | equal(Value actual,Value expected,String msg)测试数值等于预期值,不相等则断言失败 |
| void | notEqual(Value actual,Value expected,String msg)测试数值不等于预期值,相等则断言失败 |
| void | strictEqual(Value actual,Value expected,String msg)测试数值严格等于预期值,不相等则断言失败 |
| void | notStrictEqual(Value actual,Value expected,String msg)测试数值不严格等于预期值,相等则断言失败 |
| void | deepEqual(Value actual,Value expected,String msg)测试数值深度等于预期值,不相等则断言失败 |
| void | notDeepEqual(Value actual,Value expected,String msg)测试数值不深度等于预期值,相等则断言失败 |
| void | closeTo(Value actual,Value expected,Value delta,String msg)测试数值近似等于预期值,否则断言失败 |
| void | notCloseTo(Value actual,Value expected,Value delta,String msg)测试数值不近似等于预期值,否则断言失败 |
| void | lessThan(Value actual,Value expected,String msg)测试数值小于预期值,大于或等于则断言失败 |
| void | notLessThan(Value actual,Value expected,String msg)测试数值不小于预期值,小于则断言失败 |
| void | greaterThan(Value actual,Value expected,String msg)测试数值大于预期值,小于或等于则断言失败 |
| void | notGreaterThan(Value actual,Value expected,String msg)测试数值不大于预期值,大于则断言失败 |
| void | exist(Value actual,String msg)测试变量存在,为假则断言失败 |
| void | notExist(Value actual,String msg)测试变量不存在,为真则断言失败 |
| void | isTrue(Value actual,String msg)测试数值为布尔值真,否则断言失败 |
| void | isNotTrue(Value actual,String msg)测试数值不为布尔值真,否则断言失败 |
| void | isFalse(Value actual,String msg)测试数值为布尔值假,否则断言失败 |
| void | isNotFalse(Value actual,String msg)测试数值不为布尔值假,否则断言失败 |
| void | isNull(Value actual,String msg)测试数值为 Null,否则断言失败 |
| void | isNotNull(Value actual,String msg)测试数值不为 Null,否则断言失败 |
| void | isUndefined(Value actual,String msg)测试数值为 undefined,否则断言失败 |
| void | isDefined(Value actual,String msg)测试数值不为 undefined,否则断言失败 |
| void | isFunction(Value actual,String msg)测试数值为函数,否则断言失败 |
| void | isNotFunction(Value actual,String msg)测试数值不为函数,否则断言失败 |
| void | isObject(Value actual,String msg)测试数值为对象,否则断言失败 |
| void | isNotObject(Value actual,String msg)测试数值不为对象,否则断言失败 |
| void | isArray(Value actual,String msg)测试数值为数组,否则断言失败 |
| void | isNotArray(Value actual,String msg)测试数值不为数组,否则断言失败 |
| void | isString(Value actual,String msg)测试数值为字符串,否则断言失败 |
| void | isNotString(Value actual,String msg)测试数值不为字符串,否则断言失败 |
| void | isNumber(Value actual,String msg)测试数值为数字,否则断言失败 |
| void | isNotNumber(Value actual,String msg)测试数值不为数字,否则断言失败 |
| void | isBoolean(Value actual,String msg)测试数值为布尔,否则断言失败 |
| void | isNotBoolean(Value actual,String msg)测试数值不为布尔,否则断言失败 |
| void | typeOf(Value actual,String type,String msg)测试数值为给定类型,否则断言失败 |
| void | notTypeOf(Value actual,String type,String msg)测试数值不为给定类型,否则断言失败 |
| void | property(Value object,Value prop,String msg)测试对象中包含指定属性,否则断言失败 |
| void | notProperty(Value object,Value prop,String msg)测试对象中不包含指定属性,否则断言失败 |
| void | deepProperty(Value object,Value prop,String msg)深度测试对象中包含指定属性,否则断言失败 |
| void | notDeepProperty(Value object,Value prop,String msg)深度测试对象中不包含指定属性,否则断言失败 |
| void | propertyVal(Value object,Value prop,Value value,String msg)测试对象中指定属性的值为给定值,否则断言失败 |
| void | propertyNotVal(Value object,Value prop,Value value,String msg)测试对象中指定属性的值不为给定值,否则断言失败 |
| void | deepPropertyVal(Value object,Value prop,Value value,String msg)深度测试对象中指定属性的值为给定值,否则断言失败 |
| void | deepPropertyNotVal(Value object,Value prop,Value value,String msg)深度测试对象中指定属性的值不为给定值,否则断言失败 |
| void | throws(Function block,String msg)测试给定的代码会抛出错误,未抛出则断言失败 |
| void | doesNotThrow(Function block,String msg)测试给定的代码不会抛出错误,抛出则断言失败 |
Function(Value actual,String msg)测试数值为真,为假则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
ok(Value actual,String msg)测试数值为真,为假则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
notOk(Value actual,String msg)测试数值为假,为真则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
equal(Value actual,Value expected,String msg)测试数值等于预期值,不相等则断言失败
actual 要测试的数值
expected 预期的数值
msg 断言失败时的提示信息
notEqual(Value actual,Value expected,String msg)测试数值不等于预期值,相等则断言失败
actual 要测试的数值
expected 预期的数值
msg 断言失败时的提示信息
strictEqual(Value actual,Value expected,String msg)测试数值严格等于预期值,不相等则断言失败
actual 要测试的数值
expected 预期的数值
msg 断言失败时的提示信息
notStrictEqual(Value actual,Value expected,String msg)测试数值不严格等于预期值,相等则断言失败
actual 要测试的数值
expected 预期的数值
msg 断言失败时的提示信息
deepEqual(Value actual,Value expected,String msg)测试数值深度等于预期值,不相等则断言失败
actual 要测试的数值
expected 预期的数值
msg 断言失败时的提示信息
notDeepEqual(Value actual,Value expected,String msg)测试数值不深度等于预期值,相等则断言失败
actual 要测试的数值
expected 预期的数值
msg 断言失败时的提示信息
closeTo(Value actual,Value expected,Value delta,String msg)测试数值近似等于预期值,否则断言失败
actual 要测试的数值
expected 预期的数值
delta 近似的小数精度
msg 断言失败时的提示信息
notCloseTo(Value actual,Value expected,Value delta,String msg)测试数值不近似等于预期值,否则断言失败
actual 要测试的数值
expected 预期的数值
delta 近似的小数精度
msg 断言失败时的提示信息
lessThan(Value actual,Value expected,String msg)测试数值小于预期值,大于或等于则断言失败
actual 要测试的数值
expected 预期的数值
msg 断言失败时的提示信息
notLessThan(Value actual,Value expected,String msg)测试数值不小于预期值,小于则断言失败
actual 要测试的数值
expected 预期的数值
msg 断言失败时的提示信息
greaterThan(Value actual,Value expected,String msg)测试数值大于预期值,小于或等于则断言失败
actual 要测试的数值
expected 预期的数值
msg 断言失败时的提示信息
notGreaterThan(Value actual,Value expected,String msg)测试数值不大于预期值,大于则断言失败
actual 要测试的数值
expected 预期的数值
msg 断言失败时的提示信息
exist(Value actual,String msg)测试变量存在,为假则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
notExist(Value actual,String msg)测试变量不存在,为真则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isTrue(Value actual,String msg)测试数值为布尔值真,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isNotTrue(Value actual,String msg)测试数值不为布尔值真,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isFalse(Value actual,String msg)测试数值为布尔值假,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isNotFalse(Value actual,String msg)测试数值不为布尔值假,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isNull(Value actual,String msg)测试数值为 Null,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isNotNull(Value actual,String msg)测试数值不为 Null,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isUndefined(Value actual,String msg)测试数值为 undefined,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isDefined(Value actual,String msg)测试数值不为 undefined,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isFunction(Value actual,String msg)测试数值为函数,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isNotFunction(Value actual,String msg)测试数值不为函数,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isObject(Value actual,String msg)测试数值为对象,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isNotObject(Value actual,String msg)测试数值不为对象,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isArray(Value actual,String msg)测试数值为数组,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isNotArray(Value actual,String msg)测试数值不为数组,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isString(Value actual,String msg)测试数值为字符串,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isNotString(Value actual,String msg)测试数值不为字符串,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isNumber(Value actual,String msg)测试数值为数字,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isNotNumber(Value actual,String msg)测试数值不为数字,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isBoolean(Value actual,String msg)测试数值为布尔,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
isNotBoolean(Value actual,String msg)测试数值不为布尔,否则断言失败
actual 要测试的数值
msg 断言失败时的提示信息
typeOf(Value actual,String type,String msg)测试数值为给定类型,否则断言失败
actual 要测试的数值
type 指定的类型
msg 断言失败时的提示信息
notTypeOf(Value actual,String type,String msg)测试数值不为给定类型,否则断言失败
actual 要测试的数值
type 指定的类型
msg 断言失败时的提示信息
property(Value object,Value prop,String msg)测试对象中包含指定属性,否则断言失败
object 要测试的对象
prop 要测试的属性
msg 断言失败时的提示信息
notProperty(Value object,Value prop,String msg)测试对象中不包含指定属性,否则断言失败
object 要测试的对象
prop 要测试的属性
msg 断言失败时的提示信息
deepProperty(Value object,Value prop,String msg)深度测试对象中包含指定属性,否则断言失败
object 要测试的对象
prop 要测试的属性,以“.”分割
msg 断言失败时的提示信息
notDeepProperty(Value object,Value prop,String msg)深度测试对象中不包含指定属性,否则断言失败
object 要测试的对象
prop 要测试的属性,以“.”分割
msg 断言失败时的提示信息
propertyVal(Value object,Value prop,Value value,String msg)测试对象中指定属性的值为给定值,否则断言失败
object 要测试的对象
prop 要测试的属性
value 给定的值
msg 断言失败时的提示信息
propertyNotVal(Value object,Value prop,Value value,String msg)测试对象中指定属性的值不为给定值,否则断言失败
object 要测试的对象
prop 要测试的属性
value 给定的值
msg 断言失败时的提示信息
deepPropertyVal(Value object,Value prop,Value value,String msg)深度测试对象中指定属性的值为给定值,否则断言失败
object 要测试的对象
prop 要测试的属性,以“.”分割
value 给定的值
msg 断言失败时的提示信息
deepPropertyNotVal(Value object,Value prop,Value value,String msg)深度测试对象中指定属性的值不为给定值,否则断言失败
object 要测试的对象
prop 要测试的属性,以“.”分割
value 给定的值
msg 断言失败时的提示信息
throws(Function block,String msg)测试给定的代码会抛出错误,未抛出则断言失败
block 指定测试的代码,以函数形式给出
msg 断言失败时的提示信息
doesNotThrow(Function block,String msg)测试给定的代码不会抛出错误,抛出则断言失败
block 指定测试的代码,以函数形式给出
msg 断言失败时的提示信息