我正在寻找一种用 mocha 测试 Meteor Methods 的解决方案。我正在使用 Velocity 和 Mocha 包。
这是我正在尝试测试的示例方法。
Meteor.methods({
addPoints: function(userId, points) {
return Players.update(userId, { $inc: { score: +points } });
}
});
这是,我将如何使用节点调用它,我想用参数调用方法并断言在这种情况下,它返回 1 用于更新 mongo 文档
if (!(typeof MochaWeb === 'undefined')){
MochaWeb.testOnly(function(){
describe("Meteor Method: Upldating a player", function(){
// define the handler as the method we are testing
// May be this needs to be a before each.
var handler = Meteor.call("addPoints");
var userId = "1";
var points = 5;
describe("Updating a player", function() {
it("Should Add a point", function(done){
handler(userId, points, function() {
assert(handler.calledOnce);
// a way here of asserting the callback is what we expect,
// in this case we expect a return of 1
done();
});
});
});
});
});
}
谢谢