rook/val Public Public: anyone can read this; nobody can change it.
forked from benjivers/val
workbenchthis machine
Files 967e12d2fa288842a7c42ddda720f0c8a28efc34
| 1 | /** The body contract: what it names, and what it refuses. */ |
| 2 | import { expect, test } from "bun:test"; |
| 3 | import { bodyProblems, meProblems } from "./body.ts"; |
| 4 | |
| 5 | const good = { id: "a", name: "A", x: 1, y: 2, angle: 0, alive: true, hp: 100, mate: false }; |
| 6 | |
| 7 | test("a well-formed body has no problems, and each missing or mistyped field is named", () => { |
| 8 | expect(bodyProblems(good)).toEqual([]); |
| 9 | const { alive: _, ...noAlive } = good; |
| 10 | expect(bodyProblems({ ...noAlive, down: false })).toEqual(["body.alive should be a boolean, is undefined"]); |
| 11 | expect(bodyProblems({ ...good, x: NaN })).toHaveLength(1); |
| 12 | expect(bodyProblems(null)).toEqual(["body is not an object"]); |
| 13 | expect(meProblems({ id: "a" })).toContain("me.ammo should be a number, is undefined"); |
| 14 | }); |