mirror of https://github.com/nodejs/node.git
docs for assert.throws
This commit is contained in:
parent
e681abe5cb
commit
c5c1dc5dda
|
@ -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…
Reference in New Issue