fable/val Public Public: anyone can read this; nobody can change it.

forked from benjivers/val

workbenchthis machine
Files main
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
});
15
16
test("`side` may be left out, but when it is sent it is a string", () => {
17
  expect(bodyProblems({ ...good, side: "north" })).toEqual([]);
18
  expect(bodyProblems({ ...good, side: 3 })).toEqual(["body.side should be a string, is 3"]);
19
});
↑↓ navigate ↵ open esc close
↑↓ navigate ↵ open esc close

Keyboard shortcuts