docs for assert.throws

This commit is contained in:
Oleg Slobodskoi 2010-12-02 11:07:47 -08:00 committed by Ryan Dahl
parent e681abe5cb
commit c5c1dc5dda
1 changed files with 35 additions and 2 deletions

View File

@ -37,11 +37,44 @@ Tests strict non-equality, as determined by the strict not equal operator ( `!==
### assert.throws(block, [error], [message])
Expects `block` to throw an error.
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 false;
}
},
"unexpected error"
);
### assert.doesNotThrow(block, [error], [message])
Expects `block` not to throw an error.
Expects `block` not to throw an error, see assert.throws for details.
### assert.ifError(value)