diff --git a/lib/assert.js b/lib/assert.js index 6b99098c5fda35..11733493450bdc 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -278,6 +278,10 @@ function expectedException(actual, expected) { // Ignore. The instanceof check doesn't work for arrow functions. } + if (Error.isPrototypeOf(expected)) { + return false; + } + return expected.call({}, actual) === true; } diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 7e40ecb78b80c4..b6d695f5e81516 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -344,9 +344,28 @@ a.throws(makeBlock(thrower, TypeError), function(err) { } }); +// https://github.com/nodejs/node/issues/3188 +threw = false; -// GH-207. Make sure deepEqual doesn't loop forever on circular refs +try { + var ES6Error = class extends Error {}; + + var AnotherErrorType = class extends Error {}; + const functionThatThrows = function() { + throw new AnotherErrorType('foo'); + }; + + assert.throws(functionThatThrows, ES6Error); +} catch (e) { + threw = true; + assert(e instanceof AnotherErrorType, + `expected AnotherErrorType, received ${e}`); +} + +assert.ok(threw); + +// GH-207. Make sure deepEqual doesn't loop forever on circular refs var b = {}; b.b = b;