【发布时间】:2016-09-08 13:33:54
【问题描述】:
我正在使用 Mocha 和 Chai 测试我的 Node/Express API,但我无法弄清楚为什么测试没有到达 .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: '/' }));
我认为我的问题可能在于没有正式响应,而是重定向,但我不确定如何处理它。
【问题讨论】:
-
首先将
done()移动到end处理程序内部。
标签: node.js express mocha.js chai api-design