Skip to content

setOf

The comparison assertSetEquals() and setOf() both apply to Set members.

It is the one assertObjectEquals() and assertArrayEquals() use, so a Set member compares the same way whether it sits in a Set, an array or an object.

/ export const setMemberComparison = { exactObjectKeys: true, plainActualObjectsOnly: true, } as const;

/** Matcher for a Set holding exactly the expected members.

Members are compared by value, the way assertArrayEquals compares members.

Matchers are applied through assertObjectMatches, where they narrow the corresponding property type.

import { assertObjectMatches, setOf } from "@kensio/smartass";
const value: unknown = {
tags: new Set(["draft", "featured"]),
};
assertObjectMatches(value, {
tags: setOf(new Set(["draft", "featured"] as const)),
});
// value is now narrowed to an object with a Set of those two members
// {
// tags: ReadonlySet<"draft" | "featured">;
// }

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