Im trying to test an endpoint using jest,supertest and mongoose, but actually when i try to do a request using supertest it gaves an error of timeout after 5000 ms that the async callback was not invoked
// test.js
import supertest from 'supertest';
import mongoose from 'mongoose';
import app from '../../src/index';
import user from '../../src/app/models/user';
const request = supertest(app);
beforeAll(async () => {
await mongoose.connect('mongodb://localhost:27017/user', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
});
it('should list all user', async (done) => {
const response = await request.get('/');
expect(response.status).toBe(200);
done();
});
//index.js
import express from 'express';
import mongoose from 'mongoose';
import routes from './routes';
const app = express();
// mongoose.connect('mongodb://localhost:27017/usersexample', {
// useNewUrlParser: true,
// useUnifiedTopology: true,
// });
app.use(express.json());
app.use(routes);
app.listen(3000);
export default app;