Skip to content

assertObjectEquals

Assert that two objects have the same own keys and deeply equal values, with type narrowing.

Plain objects are compared recursively by value.

Arrays are compared by length and by recursively comparing each element in order.

Dates are compared by the instant they hold.

Primitive values and other objects are compared using Object.is.

import { assertObjectEquals } from "@kensio/smartass";
const user: unknown = { id: 1, name: "Ada" };
assertObjectEquals(user, { id: 1, name: "Ada" } as const);
// user is now narrowed to { readonly id: 1; readonly name: "Ada" }

Source file: src/assert/object-equals/object-equals.assert.ts