Vamsi
Vamsi

Reputation: 95

Cucumber.js TypeError: Cannot read property 'pending' of undefined

I am using Node.js, cucumber.js(globally installed) and Web Storm IDE with a simple add number scenario and I get the below error. The step definition does not have anything else other than callback.pending. any thoughts please?

TypeError: Cannot read property 'pending' of undefined at World. (/Users/wfn936/Repos/customer-svc/features/step_definitions/customer.js:6:17) at Object.invoke (/usr/local/lib/node_modules/cucumber/lib/cucumber/support_code/step_definition.js:88:14) at Object.execute (/usr/local/lib/node_modules/cucumber/lib/cucumber/ast/step.js:161:22) at Object.acceptVisitor (/usr/local/lib/node_modules/cucumber/lib/cucumber/ast/step.js:147:12) at Object.executeStep (/usr/local/lib/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:296:12) at Object.processStep (/usr/local/lib/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:291:14) at /usr/local/lib/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:129:16 at callUserFunctionAndBroadcastAfterEvent (/usr/local/lib/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:153:9) at iterate (/usr/local/lib/node_modules/cucumber/lib/cucumber/type/collection.js:55:11) at /usr/local/lib/node_modules/cucumber/lib/cucumber/type/collection.js:62:11 at Object.hear (/usr/local/lib/node_modules/cucumber/lib/cucumber/listener.js:8:9) at /usr/local/lib/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:179:52 at processItem (/usr/local/lib/node_modules/cucumber/lib/cucumber/type/collection.js:61:9) at iterate (/usr/local/lib/node_modules/cucumber/lib/cucumber/type/collection.js:53:11) at /usr/local/lib/node_modules/cucumber/lib/cucumber/type/collection.js:62:11 at Object.hear (/usr/local/lib/node_modules/cucumber/lib/cucumber/listener.js:8:9) at /usr/local/lib/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:179:52 at processItem (/usr/local/lib/node_modules/cucumber/lib/cucumber/type/collection.js:61:9) at iterate (/usr/local/lib/node_modules/cucumber/lib/cucumber/type/collection.js:53:11) at /usr/local/lib/node_modules/cucumber/lib/cucumber/type/collection.js:62:11 at Object.hear (/usr/local/lib/node_modules/cucumber/lib/cucumber/listener.js:8:9) at /usr/local/lib/node_modules/cucumber/lib/cucumber/runtime/ast_tree_walker.js:179:52 at processItem (/usr/local/lib/node_modules/cucumber/lib/cucumber/type/collection.js:61:9) at iterate (/usr/local/lib/node_modules/cucumber/lib/cucumber/type/collection.js:53:11) at /usr/local/lib/node_modules/cucumber/lib/cucumber/type/collection.js:62:11 at handleBeforeScenarioEvent (/Applications/WebStorm.app/Contents/plugins/CucumberJavaScript/lib/cucumberjs_formatter_nix.js:97:9)

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;

Upvotes: 2

Views: 2653

Answers (1)

akaRem
akaRem

Reputation: 7638

This error

TypeError: Cannot read property 'pending' of undefined at World. (/Users/wfn936/Repos/customer-svc/features/step_definitions/customer.js:6:17) at ...

happens when number of captured args doesn't match with args in provided callback

But in your case everything looks ok.

I suggest you to reinstall cucumber (maybe) Check one more time your feature and step definition file

  • do they really look like you posted?
  • do you use these files (or may be others with another content)

Note:

  • Regexps like /^I have number (\d+) and (\d+)$/ must have callbacks function (arg1, arg2, callback) {}

  • Regexps like /^I have number (\d+)$/ must have callbacks function (arg1, callback) {}

Upvotes: 1

Related Questions