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

人走茶凉 提交于 2019-11-28 05:47:29

问题


I have just begun using Cucumber (xolvio:cucumber@0.20.2_1) with Meteor to test my project, and I am having difficulty returning a value from a Meteor.methods stub I created within a step definition.

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'});
});

The log outputs a huge object that looks like the state of the system. I noticed elsewhere that someone suggested

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

    // you can use the response here

});

But when I do this in my project, cucumber logs Object [object Object] has no method 'then'.

I also tried Meteor.users.findOne({'emails.address': anemail@email.com}); within the step definition, but I am receiving the error Meteor is not defined

Any help or guidance would be greatly appreciated.

EDIT I realized that when I was logging a huge object, it was because the Meteor method _getUser wasn't returning anything. I then tried Meteor.users.find({}).fetch() and it returned an empty array, even though my meteor-cucumber collection had my user there, which is another issue I'm experiencing.


回答1:


You don't need to use this or then, the latest version of Chimp is synchronous, so you just do this:

var user = server.call('_getUser')

Just be sure to have registration.js as part of your Meteor app and not part of the test codebase.



来源:https://stackoverflow.com/questions/33760737/how-do-you-return-from-a-meteor-methods-stub-in-cucumber

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!