2016-08-01 4 views
1

저는 모카를 테스트 주자로 사용하고 Chai는 어설 션과 시논을 사용합니다. 내가 sinon를 사용하는 데 문제 , 내가 PrestigeQuoteService.js에서 테스트 할 다음 함수는 여기스텁이 값을 반환하지 않습니다.

find: function (criteria) { 
    return PrestigeQuote.find(criteria) 
     .populate('client') 
     .populate('vehicle') 
     .populate('quoteLogs'); 
    }, 

을 제기하고있는 것은, 나의 테스트 케이스 아직

describe('find()', function() { 
    describe('prestige quote found', function() { 
     before(function() { 
     sandbox = sinon.sandbox.create(); 
     var mockChain = { 
      populate: function() { 
      return this; 
      } 
     }; 
     sandbox 
      .stub(PrestigeQuote, 'find').returns(mockChain); 
     }); 

     it('should return a particular quote', function (done) { 
     PrestigeQuoteService.find({id: 1}, function (err, result) { 
      result.should.exist; 
      done(); 
     }); 
     }); 

     after(function() { 
     sandbox.restore(); 
     }); 
    }); 
    }); 

나는이 오류가있다 심지어 done()을했다고 생각하고 기본적으로 값을 반환해야합니다.

Error: timeout of 10000ms exceeded. Ensure the done() callback is being called in this test. 

답변

0

내가 mockChain

의 수익을 추가하여 해결
describe('prestige quote found', function() { 
     before(function() { 
     sandbox = sinon.sandbox.create(); 
     var err = null; 
     var mockChain = { 
      populate: function() { 
      return this; 
      }, 
      return:function() { 
      return {}; 
      } 
     }; 
     sandbox 
      .stub(PrestigeQuote, 'find').returns(mockChain); 
     }); 

     it('should return a particular prestige quote', function (done) { 
     PrestigeQuoteService.find({id: 1}, function (result) { 
      result.should.exist; 
     }); 
     done(); 
     }); 

     after(function() { 
     sandbox.restore(); 
     }); 
    }); 
0

it() 함수 내부에서 시간 초과를 사용하십시오.

describe('find()', function() { 
    describe('prestige quote found', function() { 
     before(function() { 
     sandbox = sinon.sandbox.create(); 
     var mockChain = { 
      populate: function() { 
      return this; 
      } 
     }; 
     sandbox 
      .stub(PrestigeQuote, 'find').returns(mockChain); 
     }); 

     it('should return a particular quote', function (done) { 
     this.timeout(50000); 
     PrestigeQuoteService.find({id: 1}, function (err, result) { 
      result.should.exist; 
      done(); 
     }); 
     }); 

     after(function() { 
     sandbox.restore(); 
     }); 
    }); 
    }); 
+0

그것이 내가 함수가 객체를 반환하지 않습니다 생각, 내가 시간이 문제라고 생각하지 않습니다 작동하지 않습니다, mockChain에서 수익을 추가하려고했지만 여전히 작동하지 않습니다. – user1493376

관련 문제