Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test.each #53714

Open
mbrevda opened this issue Jul 3, 2024 · 5 comments
Open

test.each #53714

mbrevda opened this issue Jul 3, 2024 · 5 comments
Labels
feature request Issues that request new features to be added to Node.js. test_runner Issues and PRs related to the test runner subsystem.

Comments

@mbrevda
Copy link

mbrevda commented Jul 3, 2024

What is the problem this feature will solve?

Allows for duplicating the same test with different data

What is the feature you are proposing to solve the problem?

test.each(list), which does a forEach on the list and runs the test once for each item

What alternatives have you considered?

Manually doing a for each. This has the drawback of more boilerplate

Prior art:
https://jestjs.io/docs/api#testeachtablename-fn-timeout
https://www.npmjs.com/package/mocha-each

@mbrevda mbrevda added the feature request Issues that request new features to be added to Node.js. label Jul 3, 2024
@RedYetiDev RedYetiDev added the test_runner Issues and PRs related to the test runner subsystem. label Jul 3, 2024
@RedYetiDev RedYetiDev self-assigned this Jul 3, 2024
@cjihrig
Copy link
Contributor

cjihrig commented Jul 3, 2024

Can you clarify the "less pretty test names" and "requires more explicit exception handling" points?

@RedYetiDev RedYetiDev removed their assignment Jul 3, 2024
@RedYetiDev
Copy link
Member

(Didn't mean to self-assign)

@mbrevda
Copy link
Author

mbrevda commented Jul 4, 2024

Sure. The signature for

Can you clarify the "less pretty test names" and "requires more explicit exception handling" points?

reviewing my current code I didn't find anything to backup those claims (I've since removed them from my post). Instead, here is an illustration of the difference. This can be currently done like:

[].forEach((i) => {
  describe(`with ${i} `, async () => {
    [].forEach((j) => {
      it(`with id ${j}`, async () => {
        assert.ok(() => true);
      });
    });
  });
});

vs how it might be done with a native support:

describe.each([])("with %i", (i) => {
  it.each([])("with id %i", async (j) => {
    assert.ok(() => true);
  });
});
@RedYetiDev
Copy link
Member

Looking at it now, it seems to only be a few more lines to implement in userland rather than in core (though initially I did suggest adding this).

@trivikr
Copy link
Member

trivikr commented Jul 11, 2024

Similar request for reference #47902

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. test_runner Issues and PRs related to the test runner subsystem.
4 participants