Cucumberjs 和 Gherkin:为什么我不能使用 "And" 和 "But" 步骤?
Cucumberjs and Gherkin: Why can not I use "And" and "But" steps?
当我尝试在 Cucumberjs 中使用步骤 "And" 或 "But" 时,出现引用错误。找不到那些对象。但是对于步骤"Given"、"When"和“那我没有问题,我可以正常工作。为什么会这样?
可以查看步骤 And:
的 Gherkin 功能示例
在the Cucumberjs's documentation中只提到我正在使用的三个步骤。
我应该怎么做才能使用这些步骤?
To Cucumber steps beginning with And or But are exactly the same kind of steps as all the others.
请看黄瓜documentation。
And
和 But
不存在用于定义步骤
(在当前版本中,v4.2.1 - https://github.com/cucumber/cucumber-js/blob/master/src/index.js)
我很确定那是设计:
由于 And
和 But
只是依赖于前面步骤的上下文的语法糖,所以我建议定义你的 步骤定义 与 Given
、When
和 Then
.
以你为例:
And('the credit card is valid', () => {...})
没有使用上下文不会告诉您该步骤是在执行 验证 还是 操作 。因此,将步骤定义为:
Given('the credit card is valid', () => {...})
当我尝试在 Cucumberjs 中使用步骤 "And" 或 "But" 时,出现引用错误。找不到那些对象。但是对于步骤"Given"、"When"和“那我没有问题,我可以正常工作。为什么会这样?
可以查看步骤 And:
的 Gherkin 功能示例在the Cucumberjs's documentation中只提到我正在使用的三个步骤。
我应该怎么做才能使用这些步骤?
To Cucumber steps beginning with And or But are exactly the same kind of steps as all the others.
请看黄瓜documentation。
And
和 But
不存在用于定义步骤
(在当前版本中,v4.2.1 - https://github.com/cucumber/cucumber-js/blob/master/src/index.js)
我很确定那是设计:
由于 And
和 But
只是依赖于前面步骤的上下文的语法糖,所以我建议定义你的 步骤定义 与 Given
、When
和 Then
.
以你为例:
And('the credit card is valid', () => {...})
没有使用上下文不会告诉您该步骤是在执行 验证 还是 操作 。因此,将步骤定义为:
Given('the credit card is valid', () => {...})