javascript - cucumber.js 并且不是一个函数

标签 javascript cucumber bdd assert

我正在练习使用 cucmber.js 通过 BDD 编写一些单元测试。 当我尝试使用“And”语句时。错误表明

TypeError: And is not a function

这是我的代码

.特征

Feature: dataTable
Scenario Outline: <a> + <b> + <c> = <answer>
  Given I had number <a>
    And I add another number <b>
  When I add with <c>   
  Then I got answer <answer>

Examples:
|a|b|c|answer|
|1|2|3|6|
|10|15|25|50|

.step定义

defineSupportCode(function({Given,When,Then,And}){
  let ans = 0;
  Given('I had number {int}', function(input){
    ans = input
  })
  And('I add another number {int}',function(input){
    ans += input
  })
  When('I add with {int}',function(input){
    ans += input
  })
  Then('I got answer {int}', function(input){
    assert.equal(ans,input)
  })
})

错误信息如下:

TypeError: Add is not a function
    at ...  // my file location
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test_cucumber@1.0.0 cucumber: `cucumber.js ./test/e2e/Features -r ./test/e2e/StepDefinition`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test_cucumber@1.0.0 cucumber script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/lab1321_mac_air/.npm/_logs/2018-01-04T08_15_28_568Z-debug.log

请问我是不是写错了。谢谢!

最佳答案

AndBut 是特征文件的语法糖——换句话说,它们是 GivenWhen< 的别名Then

定义步骤时,应使用GivenWhenThen 来描述步骤试图实现的目标(a先决条件、行动或结果),然后如果您有多个先决条件、行动或结果,请仅在您的功能文件中使用 AndBut

关于javascript - cucumber.js 并且不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48020181/

相关文章:

javascript - 错误 : [$controller:ctrlreg]

javascript - 如何在 Javascript 中正确验证电子邮件和密码

cucumber - 如何在Cucumber中访问方案和示例名称?

c# - 在 .NET 项目中使用 BDD 规范时,为什么要同时使用 SpecFlow * 和 * MSpec?

ruby - 如何使用 Rspec 模拟模型属性?

javascript - 如何等到异步回调完成后再使用检索到的数据?

javascript - 动态创建独特的按钮

ruby-on-rails-3 - 提升路线未找到错误

ruby-on-rails - 如何在 capybara 场景中添加等待条件?

unit-testing - BDD 和测试覆盖率