-
-
Notifications
You must be signed in to change notification settings - Fork 34.6k
Closed
Labels
assertIssues and PRs related to the assert subsystem.Issues and PRs related to the assert subsystem.questionIssues that look for answers.Issues that look for answers.
Description
- Version: Since assert: accommodate ES6 classes that extend Error #4166
- Platform: Darwin 16.7.0
Using ava which has a copy of node assert module I realized few tests trying to match a custom error with t.throws were failing.
assert.throws(
() => deleteItem(initialState, operation),
NotFoundObject
);Although this custom error is extending from Error class:
import ExtendableError from 'es6-error';
class CustomError extends ExtendableError {
constructor(message, httpStatusCode, data) {
super(message);
this.httpStatusCode = httpStatusCode;
this.data = data;
}
toString() {
const message = super.toString();
return (
this.data
? `${message}. Error data: ${JSON.stringify(this.data, null, 2)}`
: message
);
}
}
export class NotFoundObject extends CustomError {
constructor(objectId, objectType) {
super(`${objectType || 'Object'} with id ${objectId} does not exist`, 400);
}
}Digging into the code I found the assert is returning false if the expected error is a prototype of Error. Which doesn't make sense. It should return true since it is a prototype of Error:
if (Error.isPrototypeOf(expected)) {
return false;
}
https://github.com/nodejs/node/blob/master/lib/assert.js#L584
So, am I reading that code wrong and it should really return false?
Reference initial issue found on ava assert module: sindresorhus/core-assert#2
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
assertIssues and PRs related to the assert subsystem.Issues and PRs related to the assert subsystem.questionIssues that look for answers.Issues that look for answers.