2014-11-16 33 views
1

我有以下代码...记录在案Cuke.JS似乎不工作

// 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) 

我在这里错过了什么?

回答

0

问题与this jira issue有关。我想看到更多的想法,我们是否真的需要保持一个单一的世界文件?

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