本文介绍了使用Mocha和Super测试进行测试:测试套件外部未捕获的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用mocha和supertest测试我的api端点时,我通过了一些测试,而有些则没有.我收到的错误消息是测试套件之外的未捕获错误:未捕获错误:监听EADDRINUSE ::: 5000

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

推荐答案

即使我也遇到过同样的问题.这是因为即使在完成测试用例执行之后,supertest仍会监听端口.因此,使用--exit标志运行mocha命令.在运行npm test之前,请确保指定端口上没有正在运行的服务

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"
 },
...

这篇关于使用Mocha和Super测试进行测试:测试套件外部未捕获的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 17:01