diff options
-rw-r--r-- | lib/assert.js | 14 | ||||
-rw-r--r-- | test/parallel/test-assert.js | 4 |
2 files changed, 13 insertions, 5 deletions
diff --git a/lib/assert.js b/lib/assert.js index ea142ed01..6b99098c5 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -268,13 +268,17 @@ function expectedException(actual, expected) { if (Object.prototype.toString.call(expected) == '[object RegExp]') { return expected.test(actual); - } else if (actual instanceof expected) { - return true; - } else if (expected.call({}, actual) === true) { - return true; } - return false; + try { + if (actual instanceof expected) { + return true; + } + } catch (e) { + // Ignore. The instanceof check doesn't work for arrow functions. + } + + return expected.call({}, actual) === true; } function _throws(shouldThrow, block, expected, message) { diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index ce84eabc3..ce19462a6 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -465,4 +465,8 @@ testBlockTypeError(assert.doesNotThrow, null); testBlockTypeError(assert.throws, undefined); testBlockTypeError(assert.doesNotThrow, undefined); +// https://github.com/nodejs/node/issues/3275 +assert.throws(() => { throw 'error'; }, err => err === 'error'); +assert.throws(() => { throw Error(); }, err => err instanceof Error); + console.log('All OK'); |