用Mocha调用和测试流星方法
Calling and Testing Meteor Methods with Mocha
我正在寻找一个解决方案来测试流星方法与摩卡。我正在使用Velocity和Mocha包。
这是我想测试的一个示例方法。
Meteor.methods({
addPoints: function(userId, points) {
return Players.update(userId, { $inc: { score: +points } });
}
});
这是我使用node调用它的方式,我想用参数调用方法并断言在这种情况下,它返回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();
});
});
});
});
});
}
谢谢
假设您的测试在服务器上运行,您应该避免向方法调用发送回调。这样,Meteor方法将"同步"运行(在光纤的意义上)。
我将把描述部分重写如下:
describe('Updating a player', function () {
beforeEach(function() {
handler(userId, points)
})
it('Should Add a point', function () {
assert(handler.calledOnce)
})
})
相关文章:
- 我需要把createUser代码放在流星方法中吗
- MeteorJS使用流星调用和流星方法时的无限循环
- 插入失败:流星 1.3 中的方法并做出反应
- 如何在流星js中为对象添加方法
- 页面加载时的流星方法
- 在茉莉花中传递“this”对象流星方法
- 为流星方法设置 cron 作业
- 要打包的命名空间流星方法
- 铁路由器:通过流星方法将数据传递给客户端
- 当另一个方法正在执行时调用流星方法
- 简单流星方法茉莉测试不工作
- 流星方法无法读取属性“;quantity”;未定义的
- 服务器上的流星方法
- 流星方法调用-等待方法完成
- 使流星方法同步
- 控制台的流星方法
- 使用流星方法,但仍然得到错误
- 用Mocha调用和测试流星方法
- 包装方法 流星方法
- 怎么得到这个.userId在流星方法中的函数