-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Request] Add the ability to skip during test execution #2923
Comments
Any news or comment about this one? I've been coming across increasingly more scenarios where you would want to exit a test early and mark it as skipped, during mid execution (e.g. when asserting against prod state with expected but improper values). |
I am not against it, but it should probably be on the context, so: test('skipped', (t) => {
t.skip()
}) How should it be implemented - I don't know 🤷🏻 Maybe throw a specific exception that doesn't fail the test, but instead marks it as skipped? |
@sheremet-va We may need to use an abort signal maybe? In that case, each test case should be run in heavy concurrency so we'd be able to skip in any step! I'm just throwing ideas! |
For anyone who's looking, this is now supported
https://vitest.dev/guide/filtering.html#skipping-suites-and-tests |
@johnkingzy nope, that is not what this ticket is about. Writing your test with .skip() is not determined at execution but at prepare time. |
@timbrinded thanks for clarifying that; I haven't had to deal with this scenario before so that's good to know. I'm just curious to know, how is using vi.skip() different from using if/else to skip running subsequent expectations based on a condition. |
@johnkingzy skip if only gets checked during prepare, which is useful for disabling tests with environment variables. It does not offer the flexibility that other test frameworks like mocha have where you can skip during test execution itself. Any scenario that has non deterministic data in it, such as a fetch call to an API, might want to skip during certain situations. With vitest you simply have to return. Mocha will allow you to this.skip() |
Clear and concise description of the problem
Currently,
describe
andtest
s can be conditionally skipped usingskipIf()
properties on the top level test functions. However there are many scenarios where it is a lot cleaner, and more logical, to assess whether a test needs to be skipped only during test execution.Suggested solution
Similar to how Mocha does this, provide
test.skip()
method on the global runner context which can be used to skip tests as they are being tested.Make it so that this is callable within any part (beforeEach, beforeAll, describe, test, aftereach, afterall ) of the vitest test runner flow, and will skip that individual test or suite.
example:
Alternative
The
skipIf()
wrappers are useable but not flexible enough for many async scenarios, as they only affect whether tests get included during the gathering phase. Sometimes you may want tests to be considered skipped, instead of failed, based on responses you get.Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: