2010-10-28 14:18:16 +02:00
|
|
|
## Assert
|
|
|
|
|
|
|
|
This module is used for writing unit tests for your applications, you can
|
|
|
|
access it with `require('assert')`.
|
|
|
|
|
|
|
|
### assert.fail(actual, expected, message, operator)
|
|
|
|
|
2011-05-24 07:40:09 +02:00
|
|
|
Throws an exception that displays the values for `actual` and `expected` separated by the provided operator.
|
2010-10-28 14:18:16 +02:00
|
|
|
|
2011-10-01 13:46:49 +02:00
|
|
|
### assert(value, message), assert.ok(value, [message])
|
2010-10-28 14:18:16 +02:00
|
|
|
|
|
|
|
Tests if value is a `true` value, it is equivalent to `assert.equal(true, value, message);`
|
|
|
|
|
|
|
|
### assert.equal(actual, expected, [message])
|
|
|
|
|
2010-11-21 23:22:34 +01:00
|
|
|
Tests shallow, coercive equality with the equal comparison operator ( `==` ).
|
2010-10-28 14:18:16 +02:00
|
|
|
|
|
|
|
### assert.notEqual(actual, expected, [message])
|
|
|
|
|
|
|
|
Tests shallow, coercive non-equality with the not equal comparison operator ( `!=` ).
|
|
|
|
|
|
|
|
### assert.deepEqual(actual, expected, [message])
|
|
|
|
|
|
|
|
Tests for deep equality.
|
|
|
|
|
|
|
|
### assert.notDeepEqual(actual, expected, [message])
|
|
|
|
|
2010-11-21 23:22:34 +01:00
|
|
|
Tests for any deep inequality.
|
2010-10-28 14:18:16 +02:00
|
|
|
|
|
|
|
### assert.strictEqual(actual, expected, [message])
|
|
|
|
|
2010-11-21 23:22:34 +01:00
|
|
|
Tests strict equality, as determined by the strict equality operator ( `===` )
|
2010-10-28 14:18:16 +02:00
|
|
|
|
|
|
|
### assert.notStrictEqual(actual, expected, [message])
|
|
|
|
|
2010-11-21 23:22:34 +01:00
|
|
|
Tests strict non-equality, as determined by the strict not equal operator ( `!==` )
|
2010-10-28 14:18:16 +02:00
|
|
|
|
|
|
|
### assert.throws(block, [error], [message])
|
|
|
|
|
2010-12-02 20:07:47 +01:00
|
|
|
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) {
|
2010-12-21 18:42:52 +01:00
|
|
|
if ( (err instanceof Error) && /value/.test(err) ) {
|
|
|
|
return true;
|
2010-12-02 20:07:47 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"unexpected error"
|
|
|
|
);
|
2010-10-28 14:18:16 +02:00
|
|
|
|
|
|
|
### assert.doesNotThrow(block, [error], [message])
|
|
|
|
|
2010-12-02 20:07:47 +01:00
|
|
|
Expects `block` not to throw an error, see assert.throws for details.
|
2010-10-28 14:18:16 +02:00
|
|
|
|
|
|
|
### assert.ifError(value)
|
|
|
|
|
2010-11-18 13:00:24 +01:00
|
|
|
Tests if value is not a false value, throws if it is a true value. Useful when
|
|
|
|
testing the first argument, `error` in callbacks.
|