assert¶
This module is primarily used to write tests. It originates from this commonjs-assert module.
Functions¶
-
assert.
fail
(value, expected, message, operator)¶ Throws an exception that displays the values for value and expected separated by the provided operator. If message is undefined, “value operator expected” is used.
-
assert.
ok
(value[, message])¶ Thests if value is truthy.
-
assert.
equal
(value, expected[, message])¶ Tests shallow, coercive equality with the equal comparison operator ( == ).
-
assert.
notEqual
(value, expected[, message])¶ Tests shallow, coercive non-equality with the not equal comparison operator ( != ).
-
assert.
deepEqual
(value, expected[, message])¶ Tests for deep equality.
-
assert.
notDeepEqual
(value, expected[, message])¶ Tests for any deep inequality.
-
assert.
strictEqual
(value, expected[, message])¶ Tests strict equality, as determined by the strict equality operator ( === ).
-
assert.
notStrictEqual
(value, expected[, message])¶ Tests strict non-equality, as determined by the strict not equal operator ( !== ).
-
assert.
throws
(block[, error][, message])¶ Expects block to throw an error. error can be constructor, RegExp or validation function.
Validate instanceof using constructor:
assert.throws(function() { throw new Error("Wrong value"); }, Error);
Validate error message using RegExp:
assert.throws(function() { throw new Error("Wrong value"); }, /value/);
Custom error validation:
assert.throws(function() { throw new Error("Wrong value"); }, function(err) { if ( (err instanceof Error) && /value/.test(err) ) { return true; } }, "unexpected error");
-
assert.
doesNotThrow
(block[, message])¶ Expects block not to throw an error, see
assert.throws()
for details.