mercredi 24 février 2016

Pass the 'this' object Meteor method in Jasmine

I am trying to test a MeteorJS method with Jasmine and Velocity. The method uses the this object. I don't know how to call the method with that object The method is as follows:

Meteor.methods({
  deleteUser: function(userId) {
    if (this.userId === userId) {
      return Meteor.users.remove({
        _id: this.userId
      });
    }
  }
  ...
})

My test is given below:

it("test remove() user IDs match", function() {
    spyOn(Meteor.users, 'remove').and.callThrough();
    Meteor.call('deleteAccount', 1);
    expect(Meteor.users.remove()).toHaveBeenCalled();
});

Unfortunately, the test is failing as I don't know how to pass the value of this.userId to the method (1 in Meteor.call('deleteAccount', 1) is userId). Can anyone tell me how to pass this to Meteor methods through a Jasmine test, please?

Aucun commentaire:

Enregistrer un commentaire