Skip to content

Async / sequentially

Steps can be asynchronous because they are executed sequentially. But Scenario and ScenarioOutline are not asynchronous.

Depending on your needs, you can use scenario hooks.

Since v2.0.0 vitest-cucumber uses test.each instead of test. To follow the Gherkin convention, steps are tested one after one.

An example Scenario:

describeFeature(feature, ({ Scenario }) => {
Scenario(`Run steps sequentially`, ({ Given, And, When, Then }) => {
let count = 0
Given(`Count equals 0`, () => {
expect(count).toBe(0)
})
And(`I increase the count by 1 in a promise`, async () => {
await new Promise((resolve) => {
count++
resolve(null)
})
})
When(`I use a timeout to increase`, async () => {
await new Promise((resolve) => {
setTimeout(() => {
count++
resolve(null)
}, 1000)
})
})
Then(`At end count should be 2`, () => {
expect(count).toBe(2)
})
})
})