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
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
.