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
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答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"
},
...