Skip to content
This repository has been archived by the owner on Sep 14, 2024. It is now read-only.

Add jest's describe.each #106

Open
MagiMaster opened this issue May 20, 2020 · 2 comments
Open

Add jest's describe.each #106

MagiMaster opened this issue May 20, 2020 · 2 comments

Comments

@MagiMaster
Copy link
Collaborator

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
Copy link
Collaborator Author

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.

@amoss-roblox
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants