assert.doesNotThrow(block[, error][, message])
Asserts that the function block
does not throw an error. See assert.throws()
for more details.
When assert.doesNotThrow()
is called, it will immediately call the block
function.
If an error is thrown and it is the same type as that specified by the error
parameter, then an AssertionError
is thrown. If the error is of a different type, or if the error
parameter is undefined, the error is propagated back to the caller.
The following, for instance, will throw the TypeError
because there is no matching error type in the assertion:
assert.doesNotThrow( () => { throw new TypeError('Wrong value'); }, SyntaxError );
However, the following will result in an AssertionError
with the message 'Got unwanted exception (TypeError)..':
assert.doesNotThrow( () => { throw new TypeError('Wrong value'); }, TypeError );
If an AssertionError
is thrown and a value is provided for the message
parameter, the value of message
will be appended to the AssertionError
message:
assert.doesNotThrow( () => { throw new TypeError('Wrong value'); }, TypeError, 'Whoops' ); // Throws: AssertionError: Got unwanted exception (TypeError). Whoops
Please login to continue.