2

With a feature containing a Scenario Outline and an Example table like:

Feature: Demonstrate Issue
Scenario Outline: Parameters with spaces don't match
    Given a variable containing <var>

    Examples:
        | var         |
        | No_Spaces   |
        | Some Spaces |

I'm struggling to match the <var> in my steps using cucumber expression with cucumberjs.

I know that the {string} parameter type requires double quotes rather than the angular brackets, but I expected the anonymous type to match:

Given('a variable containing {}', function(expectedVar) {
   return true;
});

But it doesn't.

I know I can use the regex option:

Given(/^a variable containing (.*)$/, function(expectedVar) {
   return true;
});

I would just like to know where I'm going wrong in my use of the anonymous parameter type.

Des Horsley
  • 1,858
  • 20
  • 43
  • 1
    Anonymous expressions were introduced in `6.2.0` of `cucumber-expressions`. Looks like it hasn't been propagated to `cucumber-js` yet. https://github.com/cucumber/cucumber-js/blob/master/package.json#L156 – M.P. Korstanje Mar 02 '19 at 21:27
  • 1
    But for clarity you'd be better of using `Given a variable containing ""` and capture it with `a variable containing {string}` – M.P. Korstanje Mar 02 '19 at 22:24
  • Thanks that's just what I was looking for. My only concern with that is that the gherkin starts to look non standard. I believe our other projects just use , so I don't want to add the ambiguity and make people decide to use "" or depending on what project the gherkin is for. – Des Horsley Mar 03 '19 at 00:29
  • 1
    I think you should always quote your values when theyr'e not identifiers. When they're identifiers you can use `{word}` and forgo the quotes. – M.P. Korstanje Mar 03 '19 at 11:09
  • Great, thanks for the advice, there doesn't seem to be much content around this so its good to get road tested opinions. – Des Horsley Mar 03 '19 at 11:40

0 Answers0