I'm using node v6.2.0 and testing it via Mocha & Chai.
I wrote an api that when I test it with postman / website / node CLI, it works great, but when I use mocha to test it, i get an error that says:
{ [Error: connect ECONNREFUSED 127.0.0.1:4001] code: 'ECONNREFUSED', errno: 'ECONNREFUSED', syscall: 'connect', address: '127.0.0.1', port: 4001 }
Now, the thing is, that a prior test that tests the connection at http://localhost:4001
works fine...
This is the test code -
describe('/api/getAlbums', function () {
this.timeout(5000);
it('should get an array of 4 objects', function (done) {
http.get('http://localhost:4001/api/getAlbums?uid=some_uid', function (res) {
console.log(`Got response: ${res.statusCode}`);
done();
}).on('error', (e) => {
console.log(`Got error: ${e.message}`);
console.log('e', e);
done();
});
});
});
And again, when i run the same function in the CLI (without the done();
), it works fine.
I went over a lot of documentation but couldn't find anything, would love to get your assistance, Thank you.