I am trying to test authentication with mocha, supertest, and passport but I am getting connection refused error. I assume it has to do with the way I am starting my app...
var testUser = {
"email": "test@test.com",
"password": "test"
};
var app = require('../../server');
var request = require('superagent');
var user = request.agent(app);
describe('authentication api ', function() {
it('should login a user', function(done) {
user.post('/login')
.send(testUser)
.end(function(err, res) {
if(err) throw err;
done();
});
});
});
This user does exist in my mongo database. Within my server file which is two levels higher:
module.exports = app.listen(port, function() {
console.log('app listening on port: ' + port);
});
This appears to have been fixed in March of 2015. The yeoman Dafmonk Angular Fullstack generator still uses an older version of supertest. I fixed this by opening my package.json file and updating the supertest version from "~0.11.0" to "1.0.1". Then I ran: npm prune && npm install The ECONNREFUSED went away.
Check out this bug and the commit at the very end: https://github.com/visionmedia/superagent/issues/314