summaryrefslogtreecommitdiff
path: root/doc/api/assert.md
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-04-09 00:38:41 +0200
committerRuben Bridgewater <ruben@bridgewater.de>2018-04-20 00:21:33 +0200
commit7007eee6a272398054c65f2f32bdf3467a29ee9f (patch)
tree4e79e6650e57ba6d3d2a4aae5cc29a28fd21c5d0 /doc/api/assert.md
parentad1d1057f9362558fcc76b603458374f5f5a31c5 (diff)
downloadandroid-node-v8-7007eee6a272398054c65f2f32bdf3467a29ee9f.tar.gz
android-node-v8-7007eee6a272398054c65f2f32bdf3467a29ee9f.tar.bz2
android-node-v8-7007eee6a272398054c65f2f32bdf3467a29ee9f.zip
assert: validate the block return type
This makes sure the returned value when calling `block` is actually of type promise in case `assert.rejects` or `assert.doesNotReject` is called. PR-URL: https://github.com/nodejs/node/pull/19886 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Diffstat (limited to 'doc/api/assert.md')
-rw-r--r--doc/api/assert.md13
1 files changed, 9 insertions, 4 deletions
diff --git a/doc/api/assert.md b/doc/api/assert.md
index 6d96359d00..62c96801d3 100644
--- a/doc/api/assert.md
+++ b/doc/api/assert.md
@@ -387,8 +387,10 @@ function and awaits the returned promise to complete. It will then check that
the promise is not rejected.
If `block` is a function and it throws an error synchronously,
-`assert.doesNotReject()` will return a rejected Promise with that error without
-checking the error handler.
+`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.
Please note: Using `assert.doesNotReject()` is actually not useful because there
is little benefit by catching a rejection and then rejecting it again. Instead,
@@ -929,8 +931,10 @@ function and awaits the returned promise to complete. It will then check that
the promise is rejected.
If `block` is a function and it throws an error synchronously,
-`assert.rejects()` will return a rejected Promise with that error without
-checking the error handler.
+`assert.rejects()` will return a rejected Promise with that error. If the
+function does not return a promise, `assert.rejects()` will return a rejected
+Promise with an [`ERR_INVALID_RETURN_VALUE`][] error. In both cases the error
+handler is skipped.
Besides the async nature to await the completion behaves identically to
[`assert.throws()`][].
@@ -1138,6 +1142,7 @@ assert.throws(throwingFirst, /Second$/);
Due to the confusing notation, it is recommended not to use a string as the
second argument. This might lead to difficult-to-spot errors.
+[`ERR_INVALID_RETURN_VALUE`]: errors.html#errors_err_invalid_return_value
[`Class`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
[`Error.captureStackTrace`]: errors.html#errors_error_capturestacktrace_targetobject_constructoropt
[`Error`]: errors.html#errors_class_error