diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-05-03 00:23:47 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-05-10 15:27:32 +0200 |
commit | 21c3a402d486234fb00fcb130802b8fcabd97de8 (patch) | |
tree | 4442b79e74b18bc9de657a9930f6e9e5d1549804 /test/parallel/test-assert.js | |
parent | c0720570498895d06dcec4e8f01e8922a81ac78b (diff) | |
download | android-node-v8-21c3a402d486234fb00fcb130802b8fcabd97de8.tar.gz android-node-v8-21c3a402d486234fb00fcb130802b8fcabd97de8.tar.bz2 android-node-v8-21c3a402d486234fb00fcb130802b8fcabd97de8.zip |
assert: validate input stricter
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 <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'test/parallel/test-assert.js')
-rw-r--r-- | test/parallel/test-assert.js | 27 |
1 files changed, 23 insertions, 4 deletions
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'); @@ -872,6 +887,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 () => { throw 'foo'; }, @@ -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); |