2016-05-12 3 views
2

私は私のノード/ ExpressのAPIをテストするために、モカとチャイを使用していて、テストが.END()ここでチャイは

に到達していない理由を私は理解することはできませんが、テストである().ENDに達していません:

it('should authenticate successfully with user credentials', function (done) { 
    agent 
     .post('/login') 
     .set('Content-Type', 'application/x-www-form-urlencoded') 
     .send({ 'username': 'username', 'password': 'password'}) 
     .end(function (err, res) { 
      console.log(res); 
      console.log('***************************Authenticated*********************************************'); 
      expect(res).to.have.status(200); 
     }); 
    done(); 
}); 

そして、ここでは、私が当たっていますルートである:私は私の問題ではなく正式な応答が、リダイレクトが存在しないという事実であることも理解

app.post('/login', passport.authenticate('ldapauth', { successRedirect: '/' })); 

が、私はわかりませんそれをどう扱うか。

+2

'done()'を 'end'ハンドラの_inside_に移動することから始めてください。 – robertklep

答えて

2

解決策は、done()コールバックをmy.end()メソッドに移動することになりました。ありがとう@robertklep

0

int mocha非同期メソッドをテストする場合は、コールメソッドをコールバック関数で呼び出す必要があります。

it('should authenticate successfully with user credentials', function (done) { 
     agent 
      .post('/login') 
      .set('Content-Type', 'application/x-www-form-urlencoded') 
      .send({ 'username': 'username', 'password': 'password'}) 
      .end(function (err, res) { 
       console.log(res); 
       console.log('***************************Authenticated*********************************************'); 
       expect(res).to.have.status(200); 
       done(); 
      }); 

    }); 
関連する問題