mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
assert: accommodate ES6 classes that extend Error
`assert.throws()` and `assert.doesNotThrow()` blow up with a `TypeError` if used with an ES6 class that extends Error. Fixes: https://github.com/nodejs/node/issues/3188 PR-URL: https://github.com/nodejs/node/pull/4166 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
1 parent
f61412c753
commit
87181cd74c
2 files changed
+24
-1
No files matched your search
@@ -283,6 +283,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -342,9 +342,28 @@ a.throws(makeBlock(thrower, TypeError), function(err) {
|
||||
}
|
||||
});
|
||||
|
||||
// https://github.com/nodejs/node/issues/3188
|
||||
threw = false;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user