柴没有达到.end()
我正在使用摩卡和柴来testing我的节点/快递API,我不明白为什么testing没有达到.end()
这是testing:
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: '/' }));
我想我的问题可能是事实上没有正式的回应,而是一个redirect,但我不知道如何处理它。
解决scheme最终是将done()callback移到我的.end()方法中。 谢谢@robertklep
如果您正在testingasynchronous方法int mocha,则应该在callback函数中调用call方法如下。
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(); }); });