While testing my api endpoints using mocha and supertest I got some of my test passing and some are not. The error message I got was uncaught error outside test suite: Uncaught error: listen EADDRINUSE:::5000
Asked
Active
Viewed 1,359 times
0
-
Probably some tests are executed in parallel and multiple test backends try listening on port 5000. Check other answer for EADDRINUSE error, like https://stackoverflow.com/questions/9898372/how-to-fix-error-listen-eaddrinuse-while-using-nodejs – Capricorn Sep 12 '18 at 10:27
1 Answers
-1
Even I have faced same issue. This is because supertest keep on listening port even after completing the execution of test cases. So, run the mocha command with --exit
flag. Before running npm test
make sure there is no service running on the specified port
...
"scripts": {
"start": "node server.js",
"test": "mocha --exit"
},
...
![](../../users/profiles/9438572.webp)
avatar
- 41
- 6