Skip to content

Scenario Outline

A Scenario Outline should always have an Examples block, otherwise vitest-cucumber will throw an error before running unit tests.

A Scenario Outline example:

example.feature
Feature: Use ScenarioOutline with vitest-cucumber
Scenario Outline: A tale of two developers
Given two developers, John and Jane
And on a common codebase
When John makes a pull request <pull-request>
And Jane reviews it
Then Jane <approves> it
Examples:
| pull-request | approves |
| feat: add awesome feature | Approves it |
| tests: add awesome feature unit tests | Approves it |
| big commit | Requests changes |

Run Scenario Outline tests

example.spec.ts
describeFeature(featureCampagneFilter, ({ ScenarioOutline }) => {
ScenarioOutline(`A tale of two developers`, ({ Given, When, Then, And }, variables) => {
Given(`two developers, John and Jane`, () => {
// variables['pull-request']
})
And(`on a common codebase`, () => {
// variables['approves']
})
When(`John makes a pull request <pull-request>`, () => { })
And(`Jane reviews it`, () => { })
Then(`Jane <approves> it`, () => { })
})
})

When you run your tests, ScenarioOutline is runned X times. In this example, we have 3 value lines in Examples.

So it will be runned 3 times and variables contains each values:

pull-requestapproves
first runfeat: add awesome featureApproves it
second runtests: add awesome feature unit testsApproves it
last runbig commitRequests changes

Currently variables is of type any and each value is of type string.

If in your Examples you have values like 1, true, null, etc. They will always be interpreted as string.

Validation

Before running tests, vitest-cucumber checks if:

  • Scenario Outline have an Examples block
  • Examples have at least one line for values
  • each Examples variable name is used at least one time in a scenario step

Synonym

Same thing if you use Scenario Template and/or Scenarios.