2

我正在使用 Node.js、cucumber.js(全局安装)和 Web Storm IDE 以及一个简单的加号场景,我收到以下错误。除了 callback.pending 之外,步骤定义没有其他任何内容。请问有什么想法吗?

TypeError:无法在 World 读取未定义的属性“待定”。(/Users/wfn936/Repos/customer-svc/features/step_definitions/customer.js:6:17) 在 Object.invoke (/usr/local/lib/node_modules/cucumber/lib/cucumber/support_code/step_definition.js: 88:14) 在 Object.execute (/usr/local/lib/node_modules/cucumber/lib/cucumber/ast/step.js:161:22) 在 Object.acceptVisitor (/usr/local/lib/node_modules/cucumber/ lib/cucumber/ast/step.js:147:12) 在 Object.executeStep (/usr/local/lib/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:296:12) 在 Object.processStep (/ usr/local/lib/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:291:14)在/usr/local/lib/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:129:

Feature: As a math learner
  I want to add two numbers
  so that I can learn how to add

  Scenario:
    Given I have number 3 and 5
    When I add them
    Then I get 8 as result

var myStepDefinitionsWrapper = function () {
    this.Given(/^I have number (\d+) and (\d+)$/, function (arg1, arg2, callback) {
        callback.pending();
    });

    this.When(/^I add them$/, function (callback) {
        callback.pending();
    });

    this.Then(/^I get (\d+) as result$/, function (arg1, callback) {
        callback.pending();
    });
};
module.exports = myStepDefinitionsWrapper;
4

1 回答 1

1

这个错误

TypeError:无法在 World 读取未定义的属性“待定”。(/Users/wfn936/Repos/customer-svc/features/step_definitions/customer.js:6:17) 在...

当捕获的参数数量与提供的回调中的参数不匹配时发生

但在你的情况下,一切看起来都很好。

我建议您重新安装黄瓜(也许)再检查一次您的功能和步骤定义文件

  • 它们真的看起来像你发布的吗?
  • 您是否使用这些文件(或者可能是其他内容的其他文件)

笔记:

  • 正则表达式/^I have number (\d+) and (\d+)$/必须有回调function (arg1, arg2, callback) {}

  • 正则表达式/^I have number (\d+)$/必须有回调function (arg1, callback) {}

于 2015-05-16T13:47:06.260 回答