[Solved] Xolvio/meteor-cucumber: returning result of this.server.call

I am trying to call a fixture method and use its returned value in a step definition:

Step:

this.Then(/^I fill in the sms code "([^"]*)"$/, function (verificationField, callback) {
      var code = this.server.call('getSmsCodeForUser', "+467*******");
      console.log("step code: " + code);

      this.client
        .waitForExist(verificationField, 4000)
        .waitForVisible(verificationField, 2000)
        .setValue(verificationField, code)
        .call(callback);
    });

The above code prints:

step code: [object Promise]

The server method looks like this:

'getSmsCodeForUser': function (tel) {
      var user = User.findOne({ phone: tel }),
        password = Password.findOne({ user: user._id }),
        code = parseInt(password.code);

      return code;
    }

The console log in the step definition will run before the server method is finished, and using the meteors normal way of getting a callback from server methods will not work, it will only return undefined.

Thanks to “The Meteor Test Manual” the answer is:

this.server.call('getSmsCodeForUser', "+467*******").then(function(resopnse) {

    // you can use the response here

});