pi-mono/packages/schema/test/equal.test.ts
Cristina Poncela Cubeiro af79b0c3d7
feat(schema): TypeBox parity for extra types (#11833)
Adds unsafe<T>(), recursive<T>(), Validator.validate() (check plus
errors, no coercion), bigint(), equal(), validation and coercion of
TypeBox's Type.BigInt/Type.Undefined, and Static for TypeBox's Enum,
Tuple, BigInt and Undefined. Also fixes a required property set to
undefined being rejected when its schema accepts undefined, as TypeBox
allows.
2026-11-05 11:36:38 +01:00

29 lines
694 B
TypeScript

// equal(): JSON equality, a drop-in for TypeBox's Value.Equal.
import { Value } from "typebox/value";
import { describe, expect, it } from "vitest";
import { equal } from "../src/index.ts";
describe("equal", () => {
it("compares JSON values structurally, as TypeBox's Value.Equal does", () => {
const cases: [unknown, unknown][] = [
[1, 1],
["a", "b"],
[null, null],
[null, undefined],
[
{ a: 1, b: [1, { c: 2 }] },
{ b: [1, { c: 2 }], a: 1 },
],
[{ a: 1 }, { a: 1, b: 2 }],
[
[1, 2],
[2, 1],
],
[[1], { 0: 1 }],
[{}, []],
[{ a: undefined }, {}],
];
for (const [a, b] of cases) expect(equal(a, b)).toBe(Value.Equal(a, b));
});
});