You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Although this custom error is extending from Error class:
importExtendableErrorfrom'es6-error';classCustomErrorextendsExtendableError{constructor(message,httpStatusCode,data){super(message);this.httpStatusCode=httpStatusCode;this.data=data;}toString(){constmessage=super.toString();return(this.data
? `${message}. Error data: ${JSON.stringify(this.data,null,2)}`
: message);}}exportclassNotFoundObjectextendsCustomError{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;
}
Can you please provide a test case that does not contain any code besides core code?
The check as it is right now was intentional. Without a failing test case it is difficult though to see what your issue is because my test case works just fine.
Thanks everybody for taking the time dealing with this issue. As already expected, the problem was in my side 😢 On preparing a test to reproduce the error I realized the code I was working on was loading the error objects from lib directory instead of src directory. For some reason the errors would always come with Error prototype instead of the custom error type.
Anyway, I will close this issue since the assert is working properly. Again thanks for everybody's time :)
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.Although this custom error is extending from
Error
class: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 ofError
: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
The text was updated successfully, but these errors were encountered: