Module basic module

Module assert

Assert the test module, if the test value is false, an error will be reported, and the error behavior can be set to continue running or throw an error

Reference method:

1
var assert = require('assert');

Or reference through the test module:

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

Or configure through test.setup :

1
require("test").setup();

Static function

Function

The test value is true, if it is false, the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

ok

The test value is true, if it is false, the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

notOk

The test value is false, if it is true, the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

equal

The test value is equal to the expected value, if not equal, the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • expected : Value, expected value
  • msg : String, the prompt message when the assertion fails

notEqual

The test value is not equal to the expected value, and the assertion fails if it is equal

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

Call parameters:

  • actual : Value, the value to be tested
  • expected : Value, expected value
  • msg : String, the prompt message when the assertion fails

strictEqual

The test value is strictly equal to the expected value, if not equal, the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • expected : Value, expected value
  • msg : String, the prompt message when the assertion fails

notStrictEqual

The test value is not strictly equal to the expected value, and the assertion fails if it is equal

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

Call parameters:

  • actual : Value, the value to be tested
  • expected : Value, expected value
  • msg : String, the prompt message when the assertion fails

deepEqual

The test value depth is equal to the expected value, if not equal, the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • expected : Value, expected value
  • msg : String, the prompt message when the assertion fails

notDeepEqual

The test value is not depth equal to the expected value, if it is equal, the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • expected : Value, expected value
  • msg : String, the prompt message when the assertion fails

closeTo

The test value is approximately equal to the expected value, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • expected : Value, expected value
  • delta : Value, approximate decimal precision
  • msg : String, the prompt message when the assertion fails

notCloseTo

The test value is not approximately equal to the expected value, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • expected : Value, expected value
  • delta : Value, approximate decimal precision
  • msg : String, the prompt message when the assertion fails

lessThan

The test value is less than the expected value, and the assertion fails if it is greater than or equal to

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

Call parameters:

  • actual : Value, the value to be tested
  • expected : Value, expected value
  • msg : String, the prompt message when the assertion fails

notLessThan

The test value is not less than the expected value, and the assertion fails if it is less than

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

Call parameters:

  • actual : Value, the value to be tested
  • expected : Value, expected value
  • msg : String, the prompt message when the assertion fails

greaterThan

The test value is greater than the expected value, and the assertion fails if it is less than or equal to

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

Call parameters:

  • actual : Value, the value to be tested
  • expected : Value, expected value
  • msg : String, the prompt message when the assertion fails

notGreaterThan

The test value is not greater than the expected value, if greater than the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • expected : Value, expected value
  • msg : String, the prompt message when the assertion fails

exist

The test variable exists, if it is false, the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

notExist

The test variable does not exist, if it is true, the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isTrue

The test value is Boolean true, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isNotTrue

The test value is not Boolean true, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isFalse

The test value is Boolean false, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isNotFalse

The test value is not a boolean false, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isNull

The test value is Null, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isNotNull

The test value is not Null, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isUndefined

The test value is undefined, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isDefined

The test value is not undefined, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isFunction

The test value is a function, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isNotFunction

The test value is not a function, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isObject

The test value is the object, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isNotObject

The test value is not an object, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isArray

The test value is an array, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isNotArray

The test value is not an array, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isString

The test value is a string, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isNotString

The test value is not a string, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isNumber

The test value is a number, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isNotNumber

The test value is not a number, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isBoolean

The test value is Boolean, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

isNotBoolean

The test value is not Boolean, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • msg : String, the prompt message when the assertion fails

typeOf

The test value is the given type, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • type : String, specified type
  • msg : String, the prompt message when the assertion fails

notTypeOf

The test value is not a given type, otherwise the assertion fails

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

Call parameters:

  • actual : Value, the value to be tested
  • type : String, specified type
  • msg : String, the prompt message when the assertion fails

property

The test object contains the specified attribute, otherwise the assertion fails

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

Call parameters:

  • object : Value, the object to be tested
  • prop : Value, the property to be tested
  • msg : String, the prompt message when the assertion fails

notProperty

The test object does not contain the specified attribute, otherwise the assertion fails

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

Call parameters:

  • object : Value, the object to be tested
  • prop : Value, the property to be tested
  • msg : String, the prompt message when the assertion fails

deepProperty

The depth test object contains the specified attribute, otherwise the assertion fails

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

Call parameters:

  • object : Value, the object to be tested
  • prop : Value, the property to be tested, separated by "."
  • msg : String, the prompt message when the assertion fails

notDeepProperty

The specified attribute is not included in the depth test object, otherwise the assertion fails

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

Call parameters:

  • object : Value, the object to be tested
  • prop : Value, the property to be tested, separated by "."
  • msg : String, the prompt message when the assertion fails

propertyVal

The value of the specified property in the test object is the given value, otherwise the assertion fails

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

Call parameters:

  • object : Value, the object to be tested
  • prop : Value, the property to be tested
  • value : Value, given value
  • msg : String, the prompt message when the assertion fails

propertyNotVal

The value of the specified property in the test object is not a given value, otherwise the assertion fails

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

Call parameters:

  • object : Value, the object to be tested
  • prop : Value, the property to be tested
  • value : Value, given value
  • msg : String, the prompt message when the assertion fails

deepPropertyVal

The value of the specified property in the depth test object is the given value, otherwise the assertion fails

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

Call parameters:

  • object : Value, the object to be tested
  • prop : Value, the property to be tested, separated by "."
  • value : Value, given value
  • msg : String, the prompt message when the assertion fails

deepPropertyNotVal

The value of the specified property in the depth test object is not the given value, otherwise the assertion fails

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

Call parameters:

  • object : Value, the object to be tested
  • prop : Value, the property to be tested, separated by "."
  • value : Value, given value
  • msg : String, the prompt message when the assertion fails

throws

Testing the given code will throw an error, if not thrown, the assertion will fail

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

Call parameters:

  • block : Function, specify the test code, given in the form of a function
  • msg : String, the prompt message when the assertion fails

doesNotThrow

Test the given code will not throw an error, if thrown, the assertion fails

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

Call parameters:

  • block : Function, specify the test code, given in the form of a function
  • msg : String, the prompt message when the assertion fails

ifError

If the parameter is true, throw

1
static assert.ifError(Value object = undefined);

Call parameters:

  • object : Value, parameter