模块 assert

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

引用方法:

var assert = require('assert');

或者通过 test 模块引用:

var test = require('test');
var assert = test.assert;

或者通过 test.setup 配置:

require("test").setup();

静态函数

Function

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

static assert.Function(Value actual = undefined,
    String msg = "");

调用参数:


ok

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

static assert.ok(Value actual = undefined,
    String msg = "");

调用参数:


notOk

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

static assert.notOk(Value actual = undefined,
    String msg = "");

调用参数:


equal

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

static assert.equal(Value actual = undefined,
    Value expected = undefined,
    String msg = "");

调用参数:


notEqual

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

static assert.notEqual(Value actual = undefined,
    Value expected = undefined,
    String msg = "");

调用参数:


strictEqual

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

static assert.strictEqual(Value actual = undefined,
    Value expected = undefined,
    String msg = "");

调用参数:


notStrictEqual

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

static assert.notStrictEqual(Value actual = undefined,
    Value expected = undefined,
    String msg = "");

调用参数:


deepEqual

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

static assert.deepEqual(Value actual = undefined,
    Value expected = undefined,
    String msg = "");

调用参数:


notDeepEqual

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

static assert.notDeepEqual(Value actual = undefined,
    Value expected = undefined,
    String msg = "");

调用参数:


closeTo

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

static assert.closeTo(Value actual,
    Value expected,
    Value delta,
    String msg = "");

调用参数:


notCloseTo

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

static assert.notCloseTo(Value actual,
    Value expected,
    Value delta,
    String msg = "");

调用参数:


lessThan

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

static assert.lessThan(Value actual,
    Value expected,
    String msg = "");

调用参数:


notLessThan

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

static assert.notLessThan(Value actual,
    Value expected,
    String msg = "");

调用参数:


greaterThan

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

static assert.greaterThan(Value actual,
    Value expected,
    String msg = "");

调用参数:


notGreaterThan

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

static assert.notGreaterThan(Value actual,
    Value expected,
    String msg = "");

调用参数:


exist

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

static assert.exist(Value actual,
    String msg = "");

调用参数:


notExist

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

static assert.notExist(Value actual,
    String msg = "");

调用参数:


isTrue

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

static assert.isTrue(Value actual,
    String msg = "");

调用参数:


isNotTrue

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

static assert.isNotTrue(Value actual,
    String msg = "");

调用参数:


isFalse

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

static assert.isFalse(Value actual,
    String msg = "");

调用参数:


isNotFalse

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

static assert.isNotFalse(Value actual,
    String msg = "");

调用参数:


isNull

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

static assert.isNull(Value actual,
    String msg = "");

调用参数:


isNotNull

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

static assert.isNotNull(Value actual,
    String msg = "");

调用参数:


isUndefined

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

static assert.isUndefined(Value actual,
    String msg = "");

调用参数:


isDefined

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

static assert.isDefined(Value actual,
    String msg = "");

调用参数:


isFunction

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

static assert.isFunction(Value actual,
    String msg = "");

调用参数:


isNotFunction

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

static assert.isNotFunction(Value actual,
    String msg = "");

调用参数:


isObject

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

static assert.isObject(Value actual,
    String msg = "");

调用参数:


isNotObject

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

static assert.isNotObject(Value actual,
    String msg = "");

调用参数:


isArray

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

static assert.isArray(Value actual,
    String msg = "");

调用参数:


isNotArray

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

static assert.isNotArray(Value actual,
    String msg = "");

调用参数:


isString

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

static assert.isString(Value actual,
    String msg = "");

调用参数:


isNotString

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

static assert.isNotString(Value actual,
    String msg = "");

调用参数:


isNumber

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

static assert.isNumber(Value actual,
    String msg = "");

调用参数:


isNotNumber

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

static assert.isNotNumber(Value actual,
    String msg = "");

调用参数:


isBoolean

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

static assert.isBoolean(Value actual,
    String msg = "");

调用参数:


isNotBoolean

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

static assert.isNotBoolean(Value actual,
    String msg = "");

调用参数:


typeOf

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

static assert.typeOf(Value actual,
    String type,
    String msg = "");

调用参数:


notTypeOf

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

static assert.notTypeOf(Value actual,
    String type,
    String msg = "");

调用参数:


property

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

static assert.property(Value object,
    Value prop,
    String msg = "");

调用参数:


notProperty

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

static assert.notProperty(Value object,
    Value prop,
    String msg = "");

调用参数:


deepProperty

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

static assert.deepProperty(Value object,
    Value prop,
    String msg = "");

调用参数:


notDeepProperty

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

static assert.notDeepProperty(Value object,
    Value prop,
    String msg = "");

调用参数:


propertyVal

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

static assert.propertyVal(Value object,
    Value prop,
    Value value,
    String msg = "");

调用参数:


propertyNotVal

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

static assert.propertyNotVal(Value object,
    Value prop,
    Value value,
    String msg = "");

调用参数:


deepPropertyVal

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

static assert.deepPropertyVal(Value object,
    Value prop,
    Value value,
    String msg = "");

调用参数:


deepPropertyNotVal

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

static assert.deepPropertyNotVal(Value object,
    Value prop,
    Value value,
    String msg = "");

调用参数:


throws

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

static assert.throws(Function block,
    String msg = "");

调用参数:


doesNotThrow

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

static assert.doesNotThrow(Function block,
    String msg = "");

调用参数:


ifError

如果参数为真,则抛出

static assert.ifError(Value object = undefined);

调用参数: