dan.the.discloserD
Denoβ€’4y agoβ€’
7 replies
dan.the.discloser

how do I use an array of test data pairs with Deno Test?

Is there a way for me to run an array of test data pairs?

If I do it like this, it will stop after the first failure.

const data: [string, STRINGorUNDEFINED][] = [
  ["#withpound", "withpound"],
  ["nopound", "nopound"],
  [" leading space", undefined],
  ["", undefined],
];

Deno.test("truth test", () => {
  data.forEach((pair) => {
    const input = pair[0];
    const expected = pair[1];
    const actual: RETURNTYPE = parseTagLine(input);
    assertEquals(actual, expected);
  });
});


Is there something better than simple inversion?

data.forEach((pair) => {
  Deno.test("truth test", () => {
    const input = pair[0];
    const expected = pair[1];
    const actual: RETURNTYPE = parseTagLine(input);
    assertEquals(actual, expected);
  });
});

Is there a way for me to run an array of test data pairs?

If I do it like this, it will stop after the first failure.

const data: [string, STRINGorUNDEFINED][] = [
  ["#withpound", "withpound"],
  ["nopound", "nopound"],
  [" leading space", undefined],
  ["", undefined],
];

Deno.test("truth test", () => {
  data.forEach((pair) => {
    const input = pair[0];
    const expected = pair[1];
    const actual: RETURNTYPE = parseTagLine(input);
    assertEquals(actual, expected);
  });
});


Is there something better than simple inversion?

data.forEach((pair) => {
  Deno.test("truth test", () => {
    const input = pair[0];
    const expected = pair[1];
    const actual: RETURNTYPE = parseTagLine(input);
    assertEquals(actual, expected);
  });
});
Was this page helpful?