Skip to content

Rule

Note: if you have Scenario / Scenario Outline in your feature file but not inside a rule, they should be ordered before Rule.

For example, if you write a feature like this:

Feature: Run tests with Rule
Rule: I've specific Scenario
Scenario: I'm rule's scenario
Given I use vitest-cucumber
Then It know I come from a Rule
Scenario: I'm feature's scenario
Given I use vitest-cucumber
Then It know I come from a Feature

Be careful, vitest-cucumber does not use indentation. So, in this case I’m feature’s scenario Scenario is also executed within the Rule.

Rule example

Rule is like a Feature, you can declare the scenarios and their steps.

describeFeature(feature, ({Rule}) => {
Rule(`rule with scenarii`, ({RuleScenario, RuleScenarioOutline}) => {
RuleScenario(`rule scenario`, ({Given, When, Then}) => {
Given(``, () => {})
When(``, () => {})
Then(``, () => {})
})
RuleScenarioOutline(`rule scenario outline`, ({Given, When, Then, And}) => {
Given(``, () => {})
When(``, () => {})
Then(``, () => {})
And(``, () => {})
})
})
})

Hooks

If you set hooks BeforeEachScenario and/or AfterEachScenario inside describeFeature. They will be used in your rule(s) scenario(s).