Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert: accommodate ES6 classes that extend Error #4166

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
21 changes: 20 additions & 1 deletion test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down