diff options
author | Ilya Shaisultanov <ishaisultanov@shutterstock.com> | 2015-08-17 06:35:38 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-04-19 02:49:26 +0300 |
commit | c1d82ac2ff15594840e2a1b9531b506ae067ed27 (patch) | |
tree | eec676ab5fa1d8c5cae829cb4348c1fdf9e9fc5f /lib | |
parent | 9a9beefe23ddd9550f04aa4f15c50bd3fdb146dd (diff) |
assert: respect assert.doesNotThrow message.
Special handling to detect when user has supplied a custom message.
Added a test for user message.
When testing if `actual` value is an error use
`util.isError` instead of `instanceof`.
Fixes: https://github.com/nodejs/node/issues/2385
PR-URL: https://github.com/nodejs/node/pull/2407
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/assert.js | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/assert.js b/lib/assert.js index b4de551e280..7fc9e0c3426 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -330,7 +330,14 @@ function _throws(shouldThrow, block, expected, message) { fail(actual, expected, 'Missing expected exception' + message); } - if (!shouldThrow && expectedException(actual, expected)) { + const userProvidedMessage = typeof message === 'string'; + const isUnwantedException = !shouldThrow && util.isError(actual); + const isUnexpectedException = !shouldThrow && actual && !expected; + + if ((isUnwantedException && + userProvidedMessage && + expectedException(actual, expected)) || + isUnexpectedException) { fail(actual, expected, 'Got unwanted exception' + message); } |