Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import { describe, expect, it } from "@suaveplan/testing/runner";
import { ValidationError } from "../../errors/errors.js";
import { enumeration } from "./enum.js";
describe("EnumSchema", () => {
const colors = enumeration(["red", "green", "blue"] as const);
it("accepts valid enum value", { timeout: 5000 }, () => {
expect(colors.parse("red")).toBe("red");
});
it("accepts all valid values", { timeout: 5000 }, () => {
expect(colors.parse("green")).toBe("green");
expect(colors.parse("blue")).toBe("blue");
});
it("rejects invalid value", { timeout: 5000 }, () => {
expect(() => colors.parse("yellow")).toThrow(ValidationError);
});
it("returns correct error code", { timeout: 5000 }, () => {
const r = colors.safeParse("purple");
expect(r.success).toBe(false);
if (!r.success)
expect(r.error.issues[0]?.code).toBe(
"VALIDATION.ENUM.INVALID_VALUE"
);
});
it("works with numeric enum", { timeout: 5000 }, () => {
const nums = enumeration([1, 2, 3] as const);
expect(nums.parse(2)).toBe(2);
expect(nums.safeParse(4).success).toBe(false);
});
it("rejects empty string for non-empty enum", { timeout: 5000 }, () => {
expect(colors.safeParse("").success).toBe(false);
});
});