Skip to content

Hooks

vitest-cucumber provides some hooks based on existing Vitest hooks like beforeAll, afterAll, etc.

All hooks are optional.

describeFeature(feature, ({
AfterAllScenarios, AfterEachScenario, BeforeAllScenarios, BeforeEachScenario, Scenario
}) => {
BeforeAllScenarios(() => { })
BeforeEachScenario(() => { })
AfterEachScenario(() => { })
AfterAllScenarios(() => { })
})

BeforeAllScenarios

BeforeAllScenarios is run once when describeFeature is executed at the start. It’s like a beforeAll.

AfterAllScenarios

AfterAllScenarios is like afterAll. It is called when all Scenario and/or ScenarioOutline are finished.

BeforeEachScenario

BeforeEachScenario is like beforeEach. It is called before each Scenario and/or ScenarioOutline from rule or feature.

But BeforeEachScenario is not called after each Background.

Background can be considered like BeforeEachScenario but following Gherkin syntax with steps EventCounts.

AfterEachScenario

AfterEachScenario is like afterEach for each Scenario and/or ScenarioOutline from rule or feature.

AfterEachScenario is not called after each Background.

Is called before each Scenario and/or Scenario + Background “couple”.