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 da5cdc2

Browse filesBrowse files
committed
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 dfc8bed commit da5cdc2
Copy full SHA for da5cdc2

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
@@ -278,6 +278,10 @@ function expectedException(actual, expected) {
278278
// Ignore. The instanceof check doesn't work for arrow functions.
279279
}
280280

281+
if (Error.isPrototypeOf(expected)) {
282+
return false;
283+
}
284+
281285
return expected.call({}, actual) === true;
282286
}
283287

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
@@ -344,9 +344,28 @@ a.throws(makeBlock(thrower, TypeError), function(err) {
344344
}
345345
});
346346

347+
// https://github.com/nodejs/node/issues/3188
348+
threw = false;
347349

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

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

0 commit comments

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