-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Clear and concise description of the problem
Currently, describe and tests can be conditionally skipped using skipIf() 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:
describe("Generic Test Suite", function(){
test("test1", function(){
// Some state is gathered: const state
expect(const).to.be.true
})
test("test2", async function(){
// Do some lookup where value not known at initiation time
const lookupResponse = await fetch(query)
if (!lookupResponse){
vi.skip()
}
expect(lookupResponse.json().field[0]).to.equal(5)
})
})
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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.