9 lines · 562 BRaw
| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | import { firstInvalid } from "../outcomes.ts"; |
| 4 | |
| 5 | test("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 | }); |