Const
// test/tanaris/strings.test.js (excerpt)
import { describe, test, expect } from "@jest/globals";
import { tableTestName, testTimeoutMs, toTable } from "tanaris/testing/jest";
import { capitalize } from "tanaris/strings";
describe("calling `capitalize/1` on a String uppercases its first character", () => {
// prettier-ignore
const stringsAndExpectedResults = toTable([
{ str: "", expected: "" },
{ str: "a", expected: "A" },
{ str: "hello", expected: "Hello" },
]);
test.each(stringsAndExpectedResults)(
tableTestName,
({ str, expected }) => {
expect(capitalize(str)).toBe(expected);
},
testTimeoutMs
);
});
$ npm run test
PASS test/tanaris/strings.test.js
calling `capitalize/1` on a String uppercases its first character
✓ [0] { str: '', expected: '' }
✓ [1] { str: 'a', expected: 'A' }
✓ [2] { str: 'hello', expected: 'Hello' }
A standard name for Jest table test blocks. Looks best with input data that doesn’t overflow to the next line when pretty-printed.