Documentation Index
Fetch the complete documentation index at: https://bun.zhcndoc.com/llms.txt
Use this file to discover all available pages before exploring further.
检查两个对象是否深度相等。这在 Bun 的 测试运行器 中由 expect().toEqual() 内部使用。
index.tsconst a = { a: 1, b: 2, c: { d: 3 } };
const b = { a: 1, b: 2, c: { d: 3 } };
Bun.deepEquals(a, b); // true
传入第三个参数 true 以启用严格模式。这在 Bun 的 测试运行器 中由 expect().toStrictEqual() 内部使用。
以下示例在非严格模式下会返回 true,但在严格模式下会返回 false。
index.ts// undefined 值
Bun.deepEquals({}, { a: undefined }, true); // false
// 数组中的 undefined
Bun.deepEquals(["asdf"], ["asdf", undefined], true); // false
// 稀疏数组
Bun.deepEquals([, 1], [undefined, 1], true); // false
// 对象字面量 vs 具有相同属性的实例
class Foo {
a = 1;
}
Bun.deepEquals(new Foo(), { a: 1 }, true); // false
更多有用的工具请参见 文档 > API > 工具。