Skip to content

Controlla se due oggetti sono profondamente uguali. Questo è usato internamente da expect().toEqual() nel test runner di Bun.

ts
const a = { a: 1, b: 2, c: { d: 3 } };
const b = { a: 1, b: 2, c: { d: 3 } };

Bun.deepEquals(a, b); // true

Passa true come terzo argomento per abilitare la modalità strict. Questo è usato internamente da expect().toStrictEqual() nel test runner di Bun.

I seguenti esempi restituirebbero true in modalità non-strict ma false in modalità strict.

ts
// valori undefined
Bun.deepEquals({}, { a: undefined }, true); // false

// undefined negli array
Bun.deepEquals(["asdf"], ["asdf", undefined], true); // false

// array sparsi
Bun.deepEquals([, 1], [undefined, 1], true); // false

// object literal vs istanze con stesse proprietà
class Foo {
  a = 1;
}
Bun.deepEquals(new Foo(), { a: 1 }, true); // false

Vedi Docs > API > Utils per altre utilità utili.

Bun a cura di www.bunjs.com.cn