From 21c3a402d486234fb00fcb130802b8fcabd97de8 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 3 May 2018 00:23:47 +0200 Subject: assert: validate input stricter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes sure invalid `error` objects are not ignored when using `assert.throws` and `assert.rejects`. PR-URL: https://github.com/nodejs/node/pull/20481 Reviewed-By: James M Snell Reviewed-By: Matteo Collina Reviewed-By: Michaƫl Zasso --- test/parallel/test-assert.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'test/parallel/test-assert.js') diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index dba40c0a0e..d3e37afa51 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -772,6 +772,21 @@ common.expectsError( } ); +[ + 1, + false, + Symbol() +].forEach((input) => { + assert.throws( + () => assert.throws(() => {}, input), + { + code: 'ERR_INVALID_ARG_TYPE', + message: 'The "error" argument must be one of type Object, Error, ' + + `Function, or RegExp. Received type ${typeof input}` + } + ); +}); + { const errFn = () => { const err = new TypeError('Wrong value'); @@ -871,6 +886,14 @@ common.expectsError( ); } +assert.throws( + () => assert.throws(() => { throw new Error(); }, {}), + { + message: "The argument 'error' may not be an empty object. Received {}", + code: 'ERR_INVALID_ARG_VALUE' + } +); + assert.throws( () => a.throws( // eslint-disable-next-line no-throw-literal @@ -981,7 +1004,3 @@ assert.throws( } ); } - -// TODO: This case is only there to make sure there is no breaking change. -// eslint-disable-next-line no-restricted-syntax, no-throw-literal -assert.throws(() => { throw 4; }, 4); -- cgit v1.2.3