I'm testing the following endpoint:
app.post('/api/master/makeLeaderInZone', authenticateMaster, (request, response) => {
    var body = _.pick(request.body, ['zoneId', 'leaderId'])
    Zone.findById(body.zoneId).then((zone) => {
        if (zone) {
            return zone.addLeader(body.leaderId)
        } else {
            return Promise.reject()
        }
    }).then(() => {
        return Volunteer.findById(body.leaderId)
    }).then((volunteer) => {
        if (volunteer) {
            return volunteer.addToZoneAsLeader(body.zoneId)
        } else {
            return Promise.reject()
        }
    }).then(() => {
        response.status(200).send()
    }).catch((error) => {
        response.status(400).send()
    })
})
And this is the test I am using:
describe('makeLeaderInZone', () => {
    test('neither zone nor volunteer valid',  () => {
         request(app)
        .post('/api/master/makeLeaderInZone')
        .set('master-auth', 'master')
        .send().expect(400)
    })
})
This endpoint worked perfectly when I tested it using postman. However, with this test, I got the following error:
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.
As mentioned in this answer, I added the following line of code inside my test to make jest wait longer for my request to complete:
jest.setTimeout(30000);
But, I still got the exact same error. It's as if jest ignores this line and only waits for 5000ms.
What should I do to make this test work?
 
     
    