Browse Source

docs for assert.throws

v0.7.4-release
Oleg Slobodskoi 14 years ago
committed by Ryan Dahl
parent
commit
c5c1dc5dda
  1. 37
      doc/api/assert.markdown

37
doc/api/assert.markdown

@ -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)

Loading…
Cancel
Save