Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 87181cd

Browse filesBrowse files
TrottMyles Borins
authored andcommitted
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: #3188 PR-URL: #4166 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent f61412c commit 87181cd
Copy full SHA for 87181cd

File tree

Expand file treeCollapse file tree

2 files changed

+24
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+24
-1
lines changed
Open diff view settings
Collapse file

‎lib/assert.js‎

Copy file name to clipboardExpand all lines: lib/assert.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ function expectedException(actual, expected) {
283283
// Ignore. The instanceof check doesn't work for arrow functions.
284284
}
285285

286+
if (Error.isPrototypeOf(expected)) {
287+
return false;
288+
}
289+
286290
return expected.call({}, actual) === true;
287291
}
288292

Collapse file

‎test/parallel/test-assert.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-assert.js
+20-1Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,28 @@ a.throws(makeBlock(thrower, TypeError), function(err) {
342342
}
343343
});
344344

345+
// https://github.com/nodejs/node/issues/3188
346+
threw = false;
345347

346-
// GH-207. Make sure deepEqual doesn't loop forever on circular refs
348+
try {
349+
var ES6Error = class extends Error {};
350+
351+
var AnotherErrorType = class extends Error {};
347352

353+
const functionThatThrows = function() {
354+
throw new AnotherErrorType('foo');
355+
};
356+
357+
assert.throws(functionThatThrows, ES6Error);
358+
} catch (e) {
359+
threw = true;
360+
assert(e instanceof AnotherErrorType,
361+
`expected AnotherErrorType, received ${e}`);
362+
}
363+
364+
assert.ok(threw);
365+
366+
// GH-207. Make sure deepEqual doesn't loop forever on circular refs
348367
var b = {};
349368
b.b = b;
350369

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.