// a simplified model of Vitest's equality rules for plain objects, arrays and classes
function equals(a, b, strict) {
if (Object.is(a, b)) return true;
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
if (strict && Object.getPrototypeOf(a) !== Object.getPrototypeOf(b)) return false;
const keysA = Object.keys(a).filter((k) => strict || a[k] !== undefined);
const keysB = Object.keys(b).filter((k) => strict || b[k] !== undefined);
if (keysA.length !== keysB.length) return false;
return keysA.every((k) => Object.hasOwn(b, k) && equals(a[k], b[k], strict));
}
const toBe = (a, b) => Object.is(a, b);
const toEqual = (a, b) => equals(a, b, false);
const toStrictEqual = (a, b) => equals(a, b, true);
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
const saved = { id: 7, tags: ["new"] };
const loaded = { id: 7, tags: ["new"] };
console.log(toBe(saved, loaded), toEqual(saved, loaded), toBe(saved.id, loaded.id));
console.log(toEqual(new Point(1, 2), { x: 1, y: 2 }), toStrictEqual(new Point(1, 2), { x: 1, y: 2 }));
console.log(toEqual({ id: 7, note: undefined }, { id: 7 }), toStrictEqual({ id: 7, note: undefined }, { id: 7 }));
console.log(toBe(NaN, NaN), toBe(0.1 + 0.2, 0.3));