mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Compare error name and message on Bun.deepEquals and assert.deepStrictEqual (#7867)
* check error name and message on Bun.deepEquals * add tests * add test with subclass of Error
This commit is contained in:
@@ -830,6 +830,24 @@ bool Bun__deepEquals(JSC__JSGlobalObject* globalObject, JSValue v1, JSValue v2,
|
||||
|
||||
return false;
|
||||
}
|
||||
case ErrorInstanceType: {
|
||||
if (c2Type != ErrorInstanceType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (JSC::ErrorInstance* left = jsDynamicCast<JSC::ErrorInstance*>(v1)) {
|
||||
JSC::ErrorInstance* right = jsDynamicCast<JSC::ErrorInstance*>(v2);
|
||||
|
||||
if (UNLIKELY(!right)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
left->sanitizedNameString(globalObject) == right->sanitizedNameString(globalObject) &&
|
||||
left->sanitizedMessageString(globalObject) == right->sanitizedMessageString(globalObject)
|
||||
);
|
||||
}
|
||||
}
|
||||
case Int8ArrayType:
|
||||
case Uint8ArrayType:
|
||||
case Uint8ClampedArrayType:
|
||||
|
||||
@@ -161,6 +161,14 @@ test("testing Bun.deepEquals() using isEqual()", () => {
|
||||
expect(Infinity).toEqual(1 / 0);
|
||||
expect(-Infinity).toEqual(-Infinity);
|
||||
expect(-Infinity).toEqual(-1 / 0);
|
||||
|
||||
expect(Error("foo")).toEqual(Error("foo"));
|
||||
expect(Error("foo")).not.toEqual(Error("bar"));
|
||||
expect(Error("foo")).not.toEqual("foo");
|
||||
|
||||
class CustomError extends Error { constructor(message) { super(message); } };
|
||||
expect(new CustomError("foo")).not.toEqual(new CustomError("bar"));
|
||||
expect(new CustomError("foo")).toEqual(new CustomError("foo"));
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user