Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过';这';茉莉花的目标流星法_Javascript_Unit Testing_Meteor_Jasmine - Fatal编程技术网

Javascript 通过';这';茉莉花的目标流星法

Javascript 通过';这';茉莉花的目标流星法,javascript,unit-testing,meteor,jasmine,Javascript,Unit Testing,Meteor,Jasmine,我正在尝试用Jasmine和Velocity测试MeteorJS方法。该方法使用此对象。我不知道如何使用该对象调用该方法该方法如下: Meteor.methods({ deleteUser: function(userId) { if (this.userId === userId) { return Meteor.users.remove({ _id: this.userId }); } } ... }) 我的测试如下: i

我正在尝试用Jasmine和Velocity测试MeteorJS方法。该方法使用
对象。我不知道如何使用该对象调用该方法该方法如下:

Meteor.methods({
  deleteUser: function(userId) {
    if (this.userId === userId) {
      return Meteor.users.remove({
        _id: this.userId
      });
    }
  }
  ...
})
我的测试如下:

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

不幸的是,测试失败了,因为我不知道如何将
this.userId
的值传递给方法(Meteor.call('deleteAccount',1)is
userId
)。有谁能告诉我如何通过Jasmine测试将此传递给Meteor方法吗?

我相信您可以在Jasmine中手动设置此上下文:

it("test remove() user IDs match", function() {
    spyOn(Meteor.users, 'remove').and.callThrough();
    var thisContext = {userId: 1};
    var result = Meteor.methodMap.deleteAccount.call(thisContext, 1);
    expect(Meteor.users.remove()).toHaveBeenCalled();
});
如果methodMap不适用于您,您可能需要按照以下说明进行操作