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

2020-02-13 02:10发布

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条回答
手持菜刀,她持情操
2楼-- · 2020-02-13 02:59

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.

查看更多
登录 后发表回答