I am using Mocha and Chai to test my Node/Express API, and I can't figure out why the test is not reaching the .end()
Here is the test:
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();
});
And here is the route I am hitting:
app.post('/login', passport.authenticate('ldapauth', { successRedirect: '/' }));
I figure my problem may be with the fact that there is no formal response, but rather a redirect, but I am not sure how to handle it.
The solution ended up being to move the done() callback into my .end() method. Thanks @robertklep