-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Feature request: test.skipIf(condition, name, test) #3652
Comments
I don't think we'll support this for now as it doesn't seem like a necessary core feature. There is nothing that stops you from building your own wrapper for this feature, though :) |
Will look into that, thanks for the quick response 🙂 |
If anyone stumbles over the issue looking for the same thing. I ended up with skip-if. |
Here is a simple pattern for the odd one-off occasion
|
Can't figure out how to do this for asynchronous tests :( My skip condition is only available inside an asynchronous callback. |
Hi roonyh. Off the top of my head, the above would be something like:
|
Hi, Unfortunately that does not work. tests defined inside callbacks are not picked up by the runner. |
Tests have to be defined synchronously. https://jestjs.io/docs/en/troubleshooting.html#defining-tests |
@SimenB Ah. I figured this out, but could not find it documented. Thanks for pointing to it. |
You can do async work in |
I would have liked to saw this feature implemented. |
Here is what i'm doing: (process.platform === 'linux' ? it : it.skip)('should test linux code only', () => {
// this test will run on linux and be skipped on all others ...
}); Can also be used for e.g. file scopes: // assign the global `it` method based on platform
it = (process.platform === 'linux' ? it : it.skip);
// or even the global `describe` method based on platform
describe = (process.platform === 'linux' ? describe : describe.skip); |
this is my way of achieving this export const itif = (name: string, condition: () => boolean, cb) => {
it(name, (done) => {
if(condition()) {
cb(done)
} else {
console.warn(`[skipped]: ${name}`)
done();
}
})
} I created a helper function itif('should check this just registered user', () => user !== undefined, (done) => {
// you test code
}) in the above example, the PS: I ignored the |
If anyone is interested, we wrote a small extension to Jest to allow to select the OS to run the tests on nicely: https://www.npmjs.com/package/jest-os-detection 🙂 |
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. |
First of all thanks for making Jest 🙌
Do you want to request a feature or report a bug?
Request a feature. I will be happy to help out to make this happen if the feature is wanted.
What is the current behavior?
To skip test dynamically based on dynamic properties like the environment tests are running in it is necessary to wrap the body of the test or the whole test in an if statement. See example below from the jest codebase:
What is the expected behavior?
Would it be nice to be able to do
it.skipIf(condition, name, test)
andtest.skipIf(condition, name, test)
? That way the test report will show the tests as skipped instead of successful and it will be easier to detect if a skip condition is wrong.Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Node v7.7.2, Jest v20.0.4, Yarn v0.24.5, no extra jest configuration
The text was updated successfully, but these errors were encountered: