你如何从 Cucumber 中的 Meteor.methods 存根中 return

How do you return from a Meteor.methods stub in Cucumber

我刚刚开始使用 Cucumber (xolvio:cucumber@0.20.2_1) 和 Meteor 来测试我的项目,但我很难从我在其中创建的 Meteor.methods 存根返回值步骤定义。

register-user.js

this.When(/^he clicks the verification link in his email$/, function () {
        console.log(this.server.call('_getUser'));
});

registration.js

Meteor.methods({
    _getUser: function() {
        return Meteor.users.findOne({'emails.address': 'anyemail@email.com'});
});

日志输出一个巨大的object,看起来像是系统的状态。我注意到其他地方有人建议

this.server.call('aMethod').then(function(response) {

    // you can use the response here

});

但是当我在我的项目中这样做时,黄瓜日志 Object [object Object] has no method 'then'

我也在步骤定义中尝试了 Meteor.users.findOne({'emails.address': anemail@email.com});,但我收到错误 Meteor is not defined

如有任何帮助或指导,我们将不胜感激。

编辑 我意识到当我记录一个巨大的 object 时,那是因为 Meteor 方法 _getUser 没有返回任何东西。然后我尝试 Meteor.users.find({}).fetch() 并返回一个空数组,即使我的 meteor-cucumber collection 有我的用户,这是我遇到的另一个问题。

您不需要使用thisthen,最新版本的Chimp是同步的,所以您只需这样做:

var user = server.call('_getUser')

请务必将 registration.js 作为您的 Meteor 应用程序的一部分,而不是测试代码库的一部分。