记录的Cuke.JS似乎没有用

时间:2014-11-16 15:37:53

标签: cucumberjs

我有以下代码......

// support/world.js
/*jslint node: true */
"use strict";
var zombie = require('zombie');
var WorldConstructor = function WorldConstructor(callback) {
  this.browser = new zombie();
  var world = {
    visit: function(url, callback){
        this.browser.visit(url, callback);
    }
  };

  callback(world); // tell Cucumber we're finished and to use our world object instead of 'this'
};
exports.World = WorldConstructor;

// step_definition/note_steps.js
var noteStepDefinitionWrapper = function() {
    this.World = require("../support/world.js").World; // overwrite default
    // World constructor

    this.Given(/^I am on the main page$/, function(callback) {
        console.log("Step 1");
//      console.log(JSON.stringify(require("../support/world.js").World));
        this.visit('http://localhost:8080', callback);
    });

    this.When(/^I click the add button$/, function(callback) {
        console.log("Step 2")
        callback();
    });

    this.When(/^I fill out question information$/, function(callback) {
        console.log("Step 3")
        callback();
    });

    this.When(/^I click submit$/, function(callback) {
        console.log("Step 4")
        callback();
    });
    this.Then(/^I should see the new question$/, function(callback) {
        console.log("Step 5")
        callback();
    });
};
module.exports = noteStepDefinitionWrapper;

但是当我尝试运行时,我得到以下内容......

TypeError: Cannot read property 'visit' of undefined
  at Object.WorldConstructor.world.visit (***/grails-angular/src/test/features/support/world.js:8:18)

我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

问题与this jira issue有关。我想看到更多关于此问题的想法,我们真的需要保留一个单片世界文件吗?

var world = {
        visit : function(url, callback) {
              this.browser.visit(url);
              this.browser.wait(function() {
                    callback();
              });
        }.bind(this), //<-important
          ...
}