module assert
Assert the test module. If the test value is false, an error will be reported. The error reporting behavior can be set to continue running or throw an error.
Reference method:
1var assert = require('assert');
or viatestModule reference:
1
2var test = require('test');
var assert = test.assert;
or viatest.setupConfiguration:
1require("test").setup();
static function
Function
The test value is true, if it is false, the assertion fails.
1
2static assert.Function(Value actual = undefined,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
ok
The test value is true, if it is false, the assertion fails.
1
2static assert.ok(Value actual = undefined,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
notOk
If the test value is false, the assertion fails if it is true.
1
2static assert.notOk(Value actual = undefined,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
equal
The test value is equal to the expected value. If it is not equal, the assertion fails.
1
2
3static 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, prompt message when assertion fails
notEqual
If the test value is not equal to the expected value, if it is equal, the assertion fails.
1
2
3static 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, prompt message when assertion fails
strictEqual
The test value is strictly equal to the expected value. If it is not equal, the assertion fails.
1
2
3static 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, prompt message when assertion fails
notStrictEqual
The test value is not strictly equal to the expected value. If it is equal, the assertion fails.
1
2
3static 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, prompt message when assertion fails
deepEqual
The test value depth is equal to the expected value. If it is not equal, the assertion fails.
1
2
3static 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, prompt message when assertion fails
notDeepEqual
The test value is not equal to the expected value. If equal, the assertion fails.
1
2
3static 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, prompt message when assertion fails
closeTo
The test value is approximately equal to the expected value, otherwise the assertion fails
1
2
3
4static 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, prompt message when assertion fails
notCloseTo
The test value is not approximately equal to the expected value, otherwise the assertion fails
1
2
3
4static 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, prompt message when assertion fails
lessThan
If the test value is less than the expected value, if it is greater than or equal to the expected value, the assertion fails.
1
2
3static assert.lessThan(Value actual,
Value expected,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- expected: Value, expected value
- msg: String, prompt message when assertion fails
notLessThan
The test value is not less than the expected value. If it is less than the expected value, the assertion fails.
1
2
3static assert.notLessThan(Value actual,
Value expected,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- expected: Value, expected value
- msg: String, prompt message when assertion fails
greaterThan
If the test value is greater than the expected value, if it is less than or equal to the expected value, the assertion fails.
1
2
3static assert.greaterThan(Value actual,
Value expected,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- expected: Value, expected value
- msg: String, prompt message when assertion fails
notGreaterThan
The test value is not greater than the expected value. If it is greater, the assertion fails.
1
2
3static assert.notGreaterThan(Value actual,
Value expected,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- expected: Value, expected value
- msg: String, prompt message when assertion fails
exist
The test variable exists. If it is false, the assertion fails.
1
2static assert.exist(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
notExist
The test variable does not exist. If it is true, the assertion fails.
1
2static assert.notExist(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isTrue
Test value is boolean true, otherwise the assertion fails
1
2static assert.isTrue(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isNotTrue
Test value is not boolean true, otherwise the assertion fails
1
2static assert.isNotTrue(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isFalse
The test value is a boolean false, otherwise the assertion fails
1
2static assert.isFalse(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isNotFalse
Test value is not boolean false, otherwise the assertion fails
1
2static assert.isNotFalse(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isNull
The test value is Null, otherwise the assertion fails
1
2static assert.isNull(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isNotNull
The test value is not Null, otherwise the assertion fails
1
2static assert.isNotNull(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isUndefined
The test value is undefined, otherwise the assertion fails
1
2static assert.isUndefined(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isDefined
The test value is not undefined, otherwise the assertion fails
1
2static assert.isDefined(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isFunction
The test value is a function, otherwise the assertion fails
1
2static assert.isFunction(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isNotFunction
The test value is not a function, otherwise the assertion fails
1
2static assert.isNotFunction(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isObject
The test value is an object, otherwise the assertion fails
1
2static assert.isObject(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isNotObject
The test value is not an object, otherwise the assertion fails
1
2static assert.isNotObject(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isArray
The test value is an array, otherwise the assertion fails
1
2static assert.isArray(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isNotArray
The test value is not an array, otherwise the assertion fails
1
2static assert.isNotArray(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isString
The test value is a string, otherwise the assertion fails
1
2static assert.isString(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isNotString
The test value is not a string, otherwise the assertion fails
1
2static assert.isNotString(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isNumber
The test value is a number, otherwise the assertion fails
1
2static assert.isNumber(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isNotNumber
The test value is not a number, otherwise the assertion fails
1
2static assert.isNotNumber(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isBoolean
The test value is Boolean, otherwise the assertion fails
1
2static assert.isBoolean(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
isNotBoolean
The test value is not Boolean, otherwise the assertion fails
1
2static assert.isNotBoolean(Value actual,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- msg: String, prompt message when assertion fails
typeOf
Tests that the value is of the given type, otherwise the assertion fails
1
2
3static assert.typeOf(Value actual,
String type,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- type: String, the specified type
- msg: String, prompt message when assertion fails
notTypeOf
Tests that the value is not of the given type, otherwise the assertion fails
1
2
3static assert.notTypeOf(Value actual,
String type,
String msg = "");
Call parameters:
- actual: Value, the value to be tested
- type: String, the specified type
- msg: String, prompt message when assertion fails
property
The test object contains the specified attribute, otherwise the assertion fails
1
2
3static 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, prompt message when assertion fails
notProperty
The test object does not contain the specified attribute, otherwise the assertion fails
1
2
3static 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, prompt message when assertion fails
deepProperty
The depth test object contains the specified attribute, otherwise the assertion fails
1
2
3static assert.deepProperty(Value object,
Value prop,
String msg = "");
Call parameters:
- object: Value, the object to be tested
- prop: Value, the attribute to be tested, separated by "."
- msg: String, prompt message when assertion fails
notDeepProperty
The depth test object does not contain the specified attribute, otherwise the assertion fails
1
2
3static assert.notDeepProperty(Value object,
Value prop,
String msg = "");
Call parameters:
- object: Value, the object to be tested
- prop: Value, the attribute to be tested, separated by "."
- msg: String, prompt message when assertion fails
propertyVal
The value of the specified property in the test object is the given value, otherwise the assertion fails
1
2
3
4static 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, the given value
- msg: String, prompt message when assertion fails
propertyNotVal
The value of the specified attribute in the test object is not the given value, otherwise the assertion fails
1
2
3
4static 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, the given value
- msg: String, prompt message when 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
4static assert.deepPropertyVal(Value object,
Value prop,
Value value,
String msg = "");
Call parameters:
- object: Value, the object to be tested
- prop: Value, the attribute to be tested, separated by "."
- value: Value, the given value
- msg: String, prompt message when assertion fails
deepPropertyNotVal
The value of the specified attribute in the depth test object is not the given value, otherwise the assertion fails
1
2
3
4static assert.deepPropertyNotVal(Value object,
Value prop,
Value value,
String msg = "");
Call parameters:
- object: Value, the object to be tested
- prop: Value, the attribute to be tested, separated by "."
- value: Value, the given value
- msg: String, prompt message when assertion fails
throws
Tests that the given code throws an error, otherwise the assertion fails
1
2static assert.throws(Function block,
String msg = "");
Call parameters:
- block: Function, specifies the code of the test, given in the form of a function
- msg: String, prompt message when assertion fails
doesNotThrow
Tests that the given code does not throw an error, and if it does, the assertion fails
1
2static assert.doesNotThrow(Function block,
String msg = "");
Call parameters:
- block: Function, specifies the code of the test, given in the form of a function
- msg: String, prompt message when assertion fails
ifError
Throws if argument is true
1static assert.ifError(Value object = undefined);
Call parameters:
- object: Value, parameter