Jest did not exit one second after the test run has completed using express

前端 未结 5 1824
孤独总比滥情好
孤独总比滥情好 2021-02-05 14:24

I\'m using JEST for unit testing my express routes.

While running the yarn test all my test case are getting passed, but I\'m getting an error



        
5条回答
  •  無奈伤痛
    2021-02-05 15:19

    On my side, I just separate app.listen() from my app. So with express, your app finish with an export.

    // index.js
    module.exports = app;
    

    And just create another file to listen the port.

    // server.js
    const app = require('./index')
    app.listen(...)
    

    And if you import just the index (app index.js) in your tests, it should work with no extra config. Of course your need to adjust the start of your express app. It should use now server.js.

提交回复
热议问题