assertObjectMatch
import { assertObjectMatch } from "jsr:@ende/assert";function
function assertObjectMatch(actual: Record<PropertyKey, any>, expected: Record<PropertyKey, unknown>, msg?: string): voidMake an assertion that expected object is a subset of actual object,
deeply. If not, then throw a diff of the objects, with mismatching
properties highlighted.
actual: Record<PropertyKey, any>The actual value to be matched.
expected: Record<PropertyKey, unknown>The expected value to match.
msg?: stringThe optional message to display if the assertion fails.
Example: Usage
import { assertObjectMatch } from "@ende/assert";
assertObjectMatch({ foo: "bar" }, { foo: "bar" }); // Doesn't throw
assertObjectMatch({ foo: "bar" }, { foo: "baz" }); // Throws
assertObjectMatch({ foo: 1, bar: 2 }, { foo: 1 }); // Doesn't throw
assertObjectMatch({ foo: 1 }, { foo: 1, bar: 2 }); // Throws
Example: Usage with nested objects
import { assertObjectMatch } from "@ende/assert";
assertObjectMatch({ foo: { bar: 3, baz: 4 } }, { foo: { bar: 3 } }); // Doesn't throw
assertObjectMatch({ foo: { bar: 3 } }, { foo: { bar: 3, baz: 4 } }); // Throws