diff options
author | Teddy Katz <teddy.katz@gmail.com> | 2018-03-28 01:21:31 -0400 |
---|---|---|
committer | Teddy Katz <teddy.katz@gmail.com> | 2018-04-03 22:41:01 -0400 |
commit | fdb35d89605de642f316563cd552f930e06ac306 (patch) | |
tree | c7c3545496c7fb021d0104c4768dde9a47fa4bcb /test/parallel/test-assert-async.js | |
parent | 8995125c1427545118f68e82eea2a622878af875 (diff) | |
download | android-node-v8-fdb35d89605de642f316563cd552f930e06ac306.tar.gz android-node-v8-fdb35d89605de642f316563cd552f930e06ac306.tar.bz2 android-node-v8-fdb35d89605de642f316563cd552f930e06ac306.zip |
assert: ensure .rejects() disallows sync throws
This updates `assert.rejects()` to disallow any errors that are thrown
synchronously from the given function. Previously, throwing an error
would cause the same behavior as returning a rejected Promise.
Fixes: https://github.com/nodejs/node/issues/19646
PR-URL: https://github.com/nodejs/node/pull/19650
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/parallel/test-assert-async.js')
-rw-r--r-- | test/parallel/test-assert-async.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/test/parallel/test-assert-async.js b/test/parallel/test-assert-async.js index ab03a53cd3..b6b744c9b1 100644 --- a/test/parallel/test-assert-async.js +++ b/test/parallel/test-assert-async.js @@ -13,7 +13,7 @@ common.crashOnUnhandledRejection(); (async () => { await assert.rejects( - () => assert.fail(), + async () => assert.fail(), common.expectsError({ code: 'ERR_ASSERTION', type: assert.AssertionError, @@ -57,4 +57,17 @@ common.crashOnUnhandledRejection(); } ); } + + { + const THROWN_ERROR = new Error(); + + await assert.rejects(() => { + throw THROWN_ERROR; + }).then(common.mustNotCall()) + .catch( + common.mustCall((err) => { + assert.strictEqual(err, THROWN_ERROR); + }) + ); + } })().then(common.mustCall()); |