0

I am using the package Xolvio/meteor-cucumber and I'm trying to call a fixture method and use its returned value in a step definition:

Step:

And I fill in the sms code "#smsCodeVerification"

Step definition:

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.

Gravity123
  • 1,130
  • 3
  • 21
  • 39

1 Answers1

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

    // you can use the response here

});
Xolv.io
  • 2,483
  • 1
  • 15
  • 17