2016-08-01 6 views
1

私はモカをテストランナー、チャイをアサーションとシノンに使用しています。私は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

()関数内でタイムアウトを使用します。

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

関連する問題