2014-11-12 2 views
0

나는 q를 사용하고 약속 한 하나의 API를 가지고있다. 해당 API에 대한 단위 테스트 케이스를 작성해야합니다. q와 약속 때문에 응답을 보내지 않습니다. 이 내 API를q를 다루는 방법과 단위 테스트 케이스에 대한 약속

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'); 
    });   

}); 

내 테스트 케이스는 어떤 몸이 어떻게 그것을 해결하는 방법 말해 줄 수 있습니까?

답변

0

기능 수행 시점을 알 수 없으므로 테스트 할 수 없습니다. 호출자가이를 알고 있어야합니다. 할 것이다

exports.test=funtion(req,res){ 
    return savedata(req.body).saveQ().then(function(result){ // note the `return` 
     res.send(result); 
    }); 
}; 

당신이 할 : 당신의 빠른 회신

it('should save data',function(){ 
    spy=res.send=sinon.spy(); 
    return test(req,res).then(function(){ // note the return and the then 
     expect(spy.calledOnce).to.be('true'); 
    }); 
}); 
+0

감사

나는이 모카 단위 테스트입니다 있으리라 믿고있어 – Prabu

관련 문제