Luis
Luis

Reputation: 2143

Cucumberjs and Gherkin: Why can not I use "And" and "But" steps?

When I try to use the steps "And" or "But" in Cucumberjs I get a reference error. Those objects are not found. However for the Steps "Given", "When" and "Then I have no problem and I can work normally. Why does this happen?

Example of Gherkin feature where it is possible to look at the use of the step And:

enter image description here

In the Cucumberjs's documentation only mention the three Steps that I am using.

What should I do to be able to use these Steps?

enter image description here

Upvotes: 0

Views: 1340

Answers (2)

Len
Len

Reputation: 2145

And and But don't exist for defining steps (in the current version, v4.2.1 - https://github.com/cucumber/cucumber-js/blob/master/src/index.js)

And I'm pretty sure thats by design:

Since And and But are only syntactic sugar that depend on context of previous steps, so I'd recommend defining your step definitions with Given, When and Then.

From you example:

And('the credit card is valid', () => {...})

Without usage context would not tell you whether the step is doing a validation or an action. So, define the step instead as:

Given('the credit card is valid', () => {...})

Upvotes: 1

sisbilir
sisbilir

Reputation: 76

To Cucumber steps beginning with And or But are exactly the same kind of steps as all the others.

Please see cucumber documentation.

Upvotes: 0

Related Questions