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]
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, erroropt, messageopt)
static
Expects block not to throw an error, see assert.throws for details.
Arguments:
-
block
-
[error]
-
[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
actual
expected
message
operator
stackStartFunction
value
message
actual
expected
[message]
(String)
actual
expected
[message]
actual
expected
[message]
actual
expected
[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");
}, /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"
);
block
[error]
[message]
block
[error]
[message]
err