I am using supertest to test some basic route endpoints. I have the problem that if I use multiple tests in the same suite, I get time out error.
thrown: "Exceeded timeout of 5000 ms for a test.
Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."
I tried multiple methods but I can’t understand why I cannot use multiple tests in the same testing suite…
Personally I don’t think increasing the timeout is a solution. But I can be mistaken easily because is the first time i am using testing…
describe('Test create user', () => {
it('POST - /signup fail test', async () => {
const newUser = {
password: 'passw',
email: '[email protected]',
username: 'username'
};
const response = await request(app)
.post('/api/signup')
.send(newUser);
expect(response.status).toBe(400);
expect(response.body.error).toMatch(/Password must be at least 10 characters long/);
});
it('POST - /signup positive', async () => {
const newUser = {
password: 'password1234',
email: '[email protected]',
username: 'username'
};
const response = await request(app)
.post('/api/signup')
.send(newUser);
expect(response.status).toBe(500);
expect(response.body.error).toMatch(/Password must be at least 10 characters long/);
});
});
In the code above I tested firstly a falied attempt to create a user. Next, I want to test a success case.