Skip to content

Background

Background is available with 3.3.0 version.

Example

It works like Scenario and it’s available in Rule and/or Feature.

describeFeature(feature, ({Background, Scenario, Rule}) => {
Background(({Given}) => {
Given(`I'm a background`, async () => {})
})
Scenario(`Simple scenario`, ({Given, Then}) => {
Given(`I'm a scenario`, () => {})
Then(`background is run before me`, () => {})
})
Rule(`background in rule`, ({RuleBackground, RuleScenario}) => {
RuleBackground(({Given}) => {
Given(`I'm a background in a rule`, () => {})
})
RuleScenario(`Simple rule scenario`, ({Given, Then, And}) => {
Given(`I'm a rule scenario`, () => {})
Then(`feature background is run before me`, () => {})
And(`rule background is run after feature background`, () => {})
})
})
})

Background order

vitest-cucumber uses Vitest feature describe.each to run Background before Scenario/ScenarioOutline.

Example with a feature Scenario:

  • Background
  • Scenario Simple scenario

Example with a rule Scenario:

  • Background
  • RuleBackground
  • Scenario Simple rule scenario