2016-07-08 5 views
0

私はchaiの期待通りにsupertest-as-promisedを使用しようとしています。テストは次のように行く必要があります。いくつかのJSONにfoosエンドポイントを投稿し、回答者の身体は、2supertest-as-promisedとchai

it('should fail', function(){ 
    var agent = request(app) 
    agent 
     .post('/foos') 
     .send({ 
     // some JSON 
     }) 
     .then(function(){ 
     agent.get('/bars').then(function(res){ 
      console.log(res); 
      expect(res).to.have.deep.property('body.data').and.have.property('length').and.equal(3) 
     }) 
     }) 
    }) 

にconsole.logは実行されず、テストはどんな通過しないの長さを持っているbarsエンドポイントを呼び出します私は平等に書く。

答えて

0

あなたの約束は解決しますか?これを最初にチェックし、もう一度チェックすると、完了したコールバックを使ってチャイにあなたの非同期機能が終了したことを通知します:

it('should fail', function(done){ 
    var agent = request(app) 
    agent 
     .post('/foos') 
     .send({ 
     // some JSON 
     }) 
     .then(function(){ 
     agent.get('/bars').then(function(res){ 
      console.log(res); 
      expect(res).to.have.deep.property('body.data').and.have.property('length').and.equal(3) 
      done(); 
     }, function(error) { 
      console.log(error); 
     }) 
     }, function(error) { 
     console.log(error); 
     }) 
    }) 
関連する問題