Awaits the asyncFn promise or, if asyncFn is a function, immediately
calls the function and awaits the returned promise to complete. It will then
check that the promise is not rejected.
If asyncFn is a function and it throws an error synchronously,assert.doesNotReject() will return a rejected Promise with that error. If
the function does not return a promise, assert.doesNotReject() will return a
rejected Promise with an ERR_INVALID_RETURN_VALUE error. In both cases
the error handler is skipped.
Using assert.doesNotReject() is actually not useful because there is little
benefit in catching a rejection and then rejecting it again. Instead, consider
adding a comment next to the specific code path that should not reject and keep
error messages as expressive as possible.
If specified, error can be a Class,
RegExp or a validation
function. See throws for more details.
Besides the async nature to await the completion behaves identically to doesNotThrow.
Awaits the
asyncFn
promise or, ifasyncFn
is a function, immediately calls the function and awaits the returned promise to complete. It will then check that the promise is not rejected.If
asyncFn
is a function and it throws an error synchronously,assert.doesNotReject()
will return a rejectedPromise
with that error. If the function does not return a promise,assert.doesNotReject()
will return a rejectedPromise
with anERR_INVALID_RETURN_VALUE
error. In both cases the error handler is skipped.Using
assert.doesNotReject()
is actually not useful because there is little benefit in catching a rejection and then rejecting it again. Instead, consider adding a comment next to the specific code path that should not reject and keep error messages as expressive as possible.If specified,
error
can be aClass
,RegExp
or a validation function. See throws for more details.Besides the async nature to await the completion behaves identically to doesNotThrow.