I'm trying to test my express app and I need to make sure that the app is started before running any test. So I'm trying to make the app emit an event when it's ready and wait for that event in my before()
, but for some reason, I never receive the event and get Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
. What am I doing wrong ?
Index.js
const express = require('express')
const app = express()
const port = 3000
app.listen(port, function() {
console.log(`app listening on port ${port}!` )
app.emit('appStarted')
})
module.exports = app
test.js
const app = require('../index.js');
before(done => {
console.log('BEFORE')
app.on('appStarted', () => {
done()
})
});
Aucun commentaire:
Enregistrer un commentaire