Skip to content

assertSetEquals

Assert that a Set holds exactly the expected members, with type narrowing.

Members are compared by value.

Plain objects and nested arrays are compared recursively, and object keys must match exactly.

Dates are compared by the instant they hold.

Class instances and other values are compared using Object.is.

A Set finds its own members with SameValueZero, so pairing members here is a search rather than a lookup.

Order carries no meaning and is never reported.

import { assertSetEquals } from "@kensio/smartass";
const value: unknown = new Set(["draft", "featured"]);
assertSetEquals(value, new Set(["draft", "featured"] as const));
// value is now narrowed to ReadonlySet<"draft" | "featured">

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