Skip to content

Feature request: pass test additional arguments to beforeEach function #2070

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

Closed
pwalczyszyn opened this issue Mar 15, 2019 · 4 comments
Closed
Labels

Comments

@pwalczyszyn
Copy link

pwalczyszyn commented Mar 15, 2019

Issuehunt badges

Would be cool if we had access in beforeEach hook to additional arguments that can be passed to each test. Kinda like it's demonstrated in macros docs. This would allow beforeEach hook parametrisation. Like in the example below:

test.beforeEach(async (t, args) => {
  if (args.initDb) {
    // initialise db
  }
});

test('my test with args', async t => {

}, {
  initDb: true
});

There is a $40.00 open bounty on this issue. Add more on Issuehunt.

@novemberborn
Copy link
Member

Yes that makes sense to me.

@issuehunt-oss issuehunt-oss bot added the 💵 Funded on Issuehunt This issue has been funded on Issuehunt label May 15, 2019
@IssueHuntBot
Copy link

@IssueHunt has funded $40.00 to this issue.


@tryzniak
Copy link
Contributor

And I guess we should make that test arg available to all hooks? I already have it working with beforeEach hooks, need to wright tests.
/claim

@novemberborn
Copy link
Member

My approach in #2435 is to enable the construction of custom test() functions, which would include their own hooks and context construction. So you'd have a testWithDb() function. I think that's better than the solution advocated for here, so I'm closing this issue.

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

Successfully merging a pull request may close this issue.

4 participants