I am new to testing. I am using JEST to test my nodejs API's. When i am writing all the tests in one file its running properly without any error but when i am separating it its giving me port is already under use As for each file its running different node instance.
Both the files i am writing this to test
const supertest = require('supertest');
const app = require('../index');
describe('API Testing for APIs', () => {
it('Healthcheck endpoint', async () => {
const response = await supertest(app).get('/healthcheck');
expect(response.status).toBe(200);
expect(response.body.status).toBe('ok');
});
});
How i can separate my test in different files to organise my tests in better way or is there anyway to organise test files.
PS - please suggest what are the best practises to write NodeJS api tests.