Skip to content

[Request] Add the ability to skip during test execution #2923

@timbrinded

Description

@timbrinded

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions