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

Run a test only if meets a condition #11020

Closed
mbougarne opened this issue Jan 20, 2021 · 5 comments
Closed

Run a test only if meets a condition #11020

mbougarne opened this issue Jan 20, 2021 · 5 comments

Comments

@mbougarne
Copy link

🚀 Feature Proposal

Currently, if we want to run a test based on a condition we do it classically, we use if statement inside the body of the test/it function. This proposal suggests that we can add new functionality such as the only/skip ones, thus run the test if meets a condition: test.onlyIf(condition = true, 'Run it only if true')

Example

This proposal suggests that:

// Instead of this code
it('Should be true if age is larger than 18', () => {
  if(age > 18)
    {
      expect(true).toBeTruthy();
    }
});
// We can use this:
test.onlyIf(age > 18, 'Should run if age is larger than 18', () => {
  expect(true).toBeTruthy();
});

Actually, it will be useful when we try to check if a file exists to run tests against it.

@ahnpnl
Copy link
Contributor

ahnpnl commented Jan 22, 2021

I believe duplicated with #7245

@mbougarne
Copy link
Author

@ahnpnl I think it isn't, that's about skipping a test if a condition is true, but here I suggest running a test if meets a condition without using if statement inside test function it()/test().

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

github-actions bot commented May 6, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2022
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

2 participants