Skip to content

Scenario

You can use Scenario in Feature and Rule.

A Scenario example:

# example.feature
Feature: Improve my unit tests
    Scenario: Use vitest-cucumber in my unit tests
        Given Developer using feature file
        And   Using vitest-cucumber
        When  I run my unit tests
        Then  I know if I forgot a scenario
import { loadFeature, describeFeature } from '@amiceli/vitest-cucumber'
import { expect } from 'vitest'

const feature = await loadFeature('path/to/my/file.feature')

describeFeature(feature, ({ Scenario }) => {
    Scenario('Use vitest-cucumber in my unit tests', ({ Given, When, Then, And }) => {
        Given('Developer using feature file', () => {})
        And('sing vitest-cucumber', () => {})
        When('I run my unit tests', () => {})
        Then('I know if I forgot a scenario', () => {})
    })

})

In each step (Given, Then, etc.), you can access and use the Vitest TaskContext. For example:

Given('Developer using feature file', (ctx) => { 
    console.log(ctx.task.name)
    ctx.skip()
})

vitest-cucumber will check:

  • correct scenario names
  • correct step names
  • scenario is effectively called
  • scenario steps are effectively called

Same thing if you use Example.