Chai 未到达 .end()

Jk *_*sen 4 api-design mocha.js node.js express chai

我正在使用 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();
});
Run Code Online (Sandbox Code Playgroud)

这是我要走的路线:

app.post('/login', passport.authenticate('ldapauth', { successRedirect: '/' }));
Run Code Online (Sandbox Code Playgroud)

我认为我的问题可能在于没有正式回复,而是重定向,但我不知道如何处理它。

Jk *_*sen 5

解决方案最终是将 did() 回调移到我的 .end() 方法中。谢谢@robertklep