Skip to content
refs
History
9 lines · 562 BRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { firstInvalid } from "../outcomes.ts";
4
5test("firstInvalid reports the first failed field in the order given, or nothing when all pass", () => {
6 assert.deepEqual(firstInvalid({ title: undefined, body: "Too long." }), { ok: false, problem: { code: "invalid", message: "Too long.", field: "body" } });
7 assert.deepEqual(firstInvalid({ title: "Empty.", body: "Too long." })?.problem.field, "title");
8 assert.equal(firstInvalid({ title: undefined, body: undefined }), null);
9});