diff options
author | Masashi Hirano <cherrydog07@gmail.com> | 2019-04-21 17:04:04 +0900 |
---|---|---|
committer | Daniel Bevenius <daniel.bevenius@gmail.com> | 2019-04-24 10:07:09 +0200 |
commit | fb3f6005c037f9af8f435edd0d1f407266af2916 (patch) | |
tree | e78d5c169e9b3a99e42bad259aaaa0d90a1d0cf5 /test/addons | |
parent | 9b982feedf76ac51fe4ed1aaf22026cbb0df1a5e (diff) | |
download | android-node-v8-fb3f6005c037f9af8f435edd0d1f407266af2916.tar.gz android-node-v8-fb3f6005c037f9af8f435edd0d1f407266af2916.tar.bz2 android-node-v8-fb3f6005c037f9af8f435edd0d1f407266af2916.zip |
test: fix ineffective error tests
Fix tests whether errors are thrown correctly
because they are successful when error doesn't get thrown.
PR-URL: https://github.com/nodejs/node/pull/27333
Fixes: https://github.com/nodejs/node/issues/26385
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test/addons')
-rw-r--r-- | test/addons/non-node-context/test-make-buffer.js | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/test/addons/non-node-context/test-make-buffer.js b/test/addons/non-node-context/test-make-buffer.js index 9b17fa4ee9..d134f63b77 100644 --- a/test/addons/non-node-context/test-make-buffer.js +++ b/test/addons/non-node-context/test-make-buffer.js @@ -9,14 +9,15 @@ const { // Because the `Buffer` function and its protoype property only (currently) // exist in a Node.js instance’s main context, trying to create buffers from // another context throws an exception. +assert.throws( + () => makeBufferInNewContext(), + (exception) => { + assert.strictEqual(exception.constructor.name, 'Error'); + assert(!(exception.constructor instanceof Error)); -try { - makeBufferInNewContext(); -} catch (exception) { - assert.strictEqual(exception.constructor.name, 'Error'); - assert(!(exception.constructor instanceof Error)); - - assert.strictEqual(exception.code, 'ERR_BUFFER_CONTEXT_NOT_AVAILABLE'); - assert.strictEqual(exception.message, - 'Buffer is not available for the current Context'); -} + assert.strictEqual(exception.code, 'ERR_BUFFER_CONTEXT_NOT_AVAILABLE'); + assert.strictEqual(exception.message, + 'Buffer is not available for the current Context'); + return true; + } +); |