Testing with Mocha and Super test: Uncaught error outside test suite

后端 未结 1 1082
小蘑菇
小蘑菇 2021-01-28 10:12

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

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-28 10:43

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

    0 讨论(0)
提交回复
热议问题