Javascript 通过';这';茉莉花的目标流星法
我正在尝试用Jasmine和Velocity测试MeteorJS方法。该方法使用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
此
对象。我不知道如何使用该对象调用该方法该方法如下:
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)isuserId
)。有谁能告诉我如何通过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不适用于您,您可能需要按照以下说明进行操作