Files
SnapOtter/tests/unit/api/errors.test.ts
T
SnapOtter 4f0fbade6d test: expand unit test coverage (+437 tests, 17 new files)
Add comprehensive unit tests for previously uncovered API lib modules,
web stores, and plugin functions. Fix 2 pre-existing editor-store test
failures (invertSelection mask values).

Coverage: 30.3% -> 36.85% stmts (unit), 57.71% stmts (integration).
2026-05-09 07:35:27 +08:00

37 lines
1.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { formatZodErrors } from "../../../apps/api/src/lib/errors.js";
describe("formatZodErrors", () => {
it("formats single issue with path", () => {
const result = formatZodErrors([
{ path: ["width"], message: "Must be positive", code: "custom" },
]);
expect(result).toBe("width: Must be positive");
});
it("formats single issue without path", () => {
const result = formatZodErrors([{ path: [], message: "Invalid input", code: "custom" }]);
expect(result).toBe("Invalid input");
});
it("joins multiple issues with semicolons", () => {
const result = formatZodErrors([
{ path: ["width"], message: "Required", code: "custom" },
{ path: ["height"], message: "Must be positive", code: "custom" },
]);
expect(result).toBe("width: Required; height: Must be positive");
});
it("returns empty string for empty array", () => {
const result = formatZodErrors([]);
expect(result).toBe("");
});
it("joins nested paths with dots", () => {
const result = formatZodErrors([
{ path: ["settings", "quality"], message: "Too high", code: "custom" },
]);
expect(result).toBe("settings.quality: Too high");
});
});