I am new to jest and I am trying to connect my MySQL database inside the jest before all function , I think I have understood jest wrong or idk , I want to test my API's on a fake database I created with same schemas by hitting my localhost server url i am using express and typeorm i can give you this sample code
import request from 'supertest';
import { createConnection, getConnection, Connection } from 'typeorm';
import app from '../src/app';
let connection: Connection;
beforeAll(async () => {
connection = await createConnection();
});
afterAll(async () => {
await connection.close();
});
describe('GET /api/users', () => {
it('should fetch users from the database', async () => {
const response = await request(app).get('/api/users');
expect(response.status).toBe(200);
expect(response.body).toHaveLength(2);e
});
});
the problem is its not connecting to my database and is getting timed out
am I doing something wrong here? If you have encountered same problem I could use a solution
(also assume i am passing correct credentials inside the create-Connection method)