A test table lets one loop run the same check against several inputs.

test table A table-driven test stores inputs and expected outputs together so the same test logic stays compact.

Table Driven Cases

includeThird
table_cases.ts
Replay: real traced execution (multi-file project)
type Case = {
    input: string;
    expected: string;
};

function normalizeSlug(text: string): string {
    return text.trim().toLowerCase().replaceAll(" ", "-");
}

const includeThird: boolean = false;
const cases: Case[] = [
    { input: "Hello World", expected: "hello-world" },
    { input: " Type Script ", expected: "type-script" },
];

if (includeThird) {
    cases.push({ input: "Replay Data", expected: "replay-data" });
}

const passed: number = cases.filter((testCase) => normalizeSlug(testCase.input) === testCase.expected).length;

console.log(`${passed}/${cases.length}`);
type Case = {
    input: string;
    expected: string;
};

function normalizeSlug(text: string): string {
    return text.trim().toLowerCase().replaceAll(" ", "-");
}

const includeThird: boolean = true;
const cases: Case[] = [
    { input: "Hello World", expected: "hello-world" },
    { input: " Type Script ", expected: "type-script" },
];

if (includeThird) {
    cases.push({ input: "Replay Data", expected: "replay-data" });
}

const passed: number = cases.filter((testCase) => normalizeSlug(testCase.input) === testCase.expected).length;

console.log(`${passed}/${cases.length}`);
  1. includeThird ← false, cases ← [object Object],[object Object]

    7    return text.trim().toLowerCase().replaceAll(" ", "-");8}910const includeThird→ false: boolean = false;  //@includeThird=true11const cases→ [object Object],[object Object]: Case[] = [12    { input: "Hello World", expected: "hello-world" },13    { input: " Type Script ", expected: "type-script" },14];1516if (includeThird) {17    cases.push({ input: "Replay Data", expected: "replay-data" });18}1920const passed: number = cases[object Object],[object Object].filter((testCase) => normalizeSlug(testCase.input) === testCase.expected).length;
  2. function normalizeSlug(text: string): string

    pass 1 of 2
    3    expected: string;4};56function normalizeSlug(textHello World: string): string {7    return textHello World.trim().toLowerCase().replaceAll(" ", "-");8}
  3. function normalizeSlug(text: string): string

    pass 2 of 2
    3    expected: string;4};56function normalizeSlug(text Type Script : string): string {7    return text Type Script .trim().toLowerCase().replaceAll(" ", "-");8}
  4. passed ← 2

    17    cases.push({ input: "Replay Data", expected: "replay-data" });18}1920const passed→ 2: number = cases[object Object],[object Object].filter((testCase) => normalizeSlug(testCase.input) === testCase.expected).length;2122console.log(`${passed2}/${cases.length2}`);
    output2/2
  1. includeThird ← true, cases ← [object Object],[object Object]

    7    return text.trim().toLowerCase().replaceAll(" ", "-");8}910const includeThird→ true: boolean = true;11const cases→ [object Object],[object Object]: Case[] = [12    { input: "Hello World", expected: "hello-world" },13    { input: " Type Script ", expected: "type-script" },14];
  2. if (includeThird)

    13    { input: " Type Script ", expected: "type-script" },14];1516if (includeThirdtrue) {17    cases.push({ input: "Replay Data", expected: "replay-data" });18}
    values this step[object Object],[object Object]cases
  3. const passed: number = cases.filter((testCase) => normalizeSlug(testCa…

    17    cases.push({ input: "Replay Data", expected: "replay-data" });18}1920const passed: number = cases[object Object],[object Object],[object Object].filter((testCase) => normalizeSlug(testCase.input) === testCase.expected).length;
  4. function normalizeSlug(text: string): string

    pass 1 of 3
    3    expected: string;4};56function normalizeSlug(textHello World: string): string {7    return textHello World.trim().toLowerCase().replaceAll(" ", "-");8}
    All 3 passes — pass 1 is the card above
    passtext
    1Hello World
    2 Type Script
    3Replay Data
  5. passed ← 3

    17    cases.push({ input: "Replay Data", expected: "replay-data" });18}1920const passed→ 3: number = cases[object Object],[object Object],[object Object].filter((testCase) => normalizeSlug(testCase.input) === testCase.expected).length;2122console.log(`${passed3}/${cases.length3}`);
    output3/3