Skip to content

Support for Parameter Types in Scenario OutlineΒ #276

@tillkrischermaterna

Description

@tillkrischermaterna

πŸ€” What's the problem you're trying to solve?

I want to be able to go to definition from the Given today is <day> line in the following setup:

friday.feature

Feature: Is it Friday yet?
  Everybody wants to know when it's Friday

  Scenario Outline: Today is or is not Friday
    Given today is <day>
    When I ask whether it's Friday yet
    Then I should be told "<answer>"

    Examples:
      | day            | answer |
      | Friday         | TGIF   |
      | Sunday         | Nope   |

steps.js

import { strictEqual } from 'assert'
import { Given, When, Then, defineParameterType } from '@cucumber/cucumber';

defineParameterType({
  regexp: /Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday/,
  name: 'day',
  transformer: s => s
})

function isItFriday(today) {
  if (today === "Friday") {
    return "TGIF";
  } else {
    return "Nope";
  }
}

Given('today is {day}', function(givenDay) {
  this.today = givenDay;
});

When('I ask whether it\'s Friday yet', function() {
  this.actualAnswer = isItFriday(this.today);
});

Then('I should be told {string}', function(expectedAnswer) {
  strictEqual(this.actualAnswer, expectedAnswer);
});

✨ What's your proposed solution?

Plug in the values of the first scenario into the step and match using that.

⛏ Have you considered any alternatives or workarounds?

No response

πŸ“š Any additional context?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions