This module is used for writing unit tests for your applications, you can access it with
require('assert')
.
This is port of NodeJS NodeJS.assert module - see detailed documentation thereMembers
assert
inner
Tests if value is truthy, it is equivalent to assert.equal(true, !!value, message);
Methods
fail(actual, expected, message, operator, stackStartFunction)
inner
Throws an exception that displays the values for actual and expected separated by the provided operator.
Arguments:
-
actual
-
expected
-
message
-
operator
-
stackStartFunction
ok(value, message)
inner
Tests if value is truthy, it is equivalent to assert.equal(true, !!value, message);
Arguments:
-
value
-
message
equal(actual, expected, messageopt)
static
Tests shallow, coercive equality with the equal comparison operator ( == ).
Arguments:
-
actual
-
expected
-
[message]
(String)
notEqual(actual, expected, messageopt)
static
Tests shallow, coercive non-equality with the not equal comparison operator ( != ).
Arguments:
-
actual
-
expected
-
[message]
deepEqual(actual, expected, messageopt)
static
Tests for deep equality.
Arguments:
-
actual
-
expected
-
[message]
notDeepEqual(actual, expected, messageopt)
static
Tests for any deep inequality.
Arguments:
-
actual
-
expected
-
[message]
strictEqual(actual, expected, messageopt)
static
Tests strict equality, as determined by the strict equality operator ( === )
Arguments:
-
actual
-
expected
-
[message]
notStrictEqual(actual, expected, messageopt)
static
Tests strict non-equality, as determined by the strict not equal operator ( !== )
Arguments:
-
actual
-
expected
-
[message]
throws(block, erroropt, messageopt)
static
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");
}, /error/);
Custom error validation:
assert.throws(
function() {
throw new Error("Wrong value");
},
function(err) {
if ( (err instanceof Error) && /value/.test(err) ) {
return true;
}
},
"unexpected error"
);
Arguments:
-
block
-
[error]
-
[message]
doesNotThrow(block, messageopt)
static
Expects block not to throw an error, see assert.throws for details.
Arguments:
-
block
-
[message]
ifError(err)
static
Tests if value is not a false value, throws if it is a true value. Useful when testing the first argument, error in callbacks.
Arguments:
-
err
fail(actual, expected, message, operator, stackStartFunction) inner
Throws an exception that displays the values for actual and expected separated by the provided operator.
Arguments:
-
actual
-
expected
-
message
-
operator
-
stackStartFunction
ok(value, message) inner
Tests if value is truthy, it is equivalent to assert.equal(true, !!value, message);
Arguments:
-
value
-
message
equal(actual, expected, messageopt) static
Tests shallow, coercive equality with the equal comparison operator ( == ).
Arguments:
-
actual
-
expected
-
[message]
(String)
notEqual(actual, expected, messageopt) static
Tests shallow, coercive non-equality with the not equal comparison operator ( != ).
Arguments:
-
actual
-
expected
-
[message]
deepEqual(actual, expected, messageopt) static
Tests for deep equality.
Arguments:
-
actual
-
expected
-
[message]
notDeepEqual(actual, expected, messageopt) static
Tests for any deep inequality.
Arguments:
-
actual
-
expected
-
[message]
strictEqual(actual, expected, messageopt) static
Tests strict equality, as determined by the strict equality operator ( === )
Arguments:
-
actual
-
expected
-
[message]
notStrictEqual(actual, expected, messageopt) static
Tests strict non-equality, as determined by the strict not equal operator ( !== )
Arguments:
-
actual
-
expected
-
[message]
throws(block, erroropt, messageopt) static
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");
}, /error/);
Custom error validation:
assert.throws(
function() {
throw new Error("Wrong value");
},
function(err) {
if ( (err instanceof Error) && /value/.test(err) ) {
return true;
}
},
"unexpected error"
);
Arguments:
-
block
-
[error]
-
[message]
doesNotThrow(block, messageopt) static
Expects block not to throw an error, see assert.throws for details.
Arguments:
-
block
-
[message]
ifError(err) static
Tests if value is not a false value, throws if it is a true value. Useful when testing the first argument, error in callbacks.
Arguments:
-
err