testez icon indicating copy to clipboard operation
testez copied to clipboard

Add jest's describe.each

Open MagiMaster opened this issue 5 years ago • 2 comments

describe.each lets you pass in a table to parameterize any tests inside that describe block. Their example:

describe.each([
  [1, 1, 2],
  [1, 2, 3],
  [2, 1, 3],
])('.add(%i, %i)', (a, b, expected) => {
  test(`returns ${expected}`, () => {
    expect(a + b).toBe(expected);
  });

  test(`returned value not be greater than ${expected}`, () => {
    expect(a + b).not.toBeGreaterThan(expected);
  });

  test(`returned value not be less than ${expected}`, () => {
    expect(a + b).not.toBeLessThan(expected);
  });
});

For TestEZ, the format would probably need to be adapted a bit, and I don't like the idea of having describe() and describe.each() (describe is both a function and an object). Maybe describeEach() would fit our style better.

MagiMaster avatar May 20 '20 20:05 MagiMaster

Worth noting that you can just put a describe block inside a for loop and parameterize tests that way, so this would only be to reduce boilerplate/extra indents, and to better document the intention.

MagiMaster avatar May 20 '20 22:05 MagiMaster

Also consider it.each to avoid an extra indent if you don't need multiple cases for each input.

amoss-roblox avatar May 28 '20 15:05 amoss-roblox