【发布时间】:2014-11-12 07:08:58
【问题描述】:
我有一个使用 q 和 promise 创建的 api。我需要为该 api 编写单元测试用例。但由于 q 和 promises ,它没有发送响应。 这是我的api
exports.test=funtion(req,res)
{
savedata(req.body).saveQ().then(function(result)
{
res.send(result);
});
}
这是我对上述 api 的测试用例
var req={'body':{name:'xxxxx'}};
var res={};
describe('savedata',function()
{
it('should save data',function(){
spy=res.send=sinon.spy();
test(req,res);
expect(spy.calledOnce).to.be('true');
});
});
谁能告诉我如何解决?
【问题讨论】:
标签: javascript node.js unit-testing promise sinon