I am using setTimeout in mocha test suite to insert a 20 seconds delay before making the last post call of the it() in the describe block. Although, I am using done() , still I am getting below error on terminal :
error: timeout of 2000ms exceeded. for async tests and hooks, ensure "done()" is called; if returning a promise, ensure it resolves error: timeout of 2000ms exceeded. for async tests and hooks, ensure "done()" is called; if returning a promise, ensure it resolves
What am I doing wrong?
Below is my code :
describe('Testing get and post APIs', ()=> {
it('Series of get and post', (done) => {
chai.request(server)
.post('/thisis/1st_post')
.send()
.end((err, res) => {
expect(res.statusCode).to.equal(200);
chai.request(server)
.get('/thisis/1st_get')
.send()
.end((err, res) => {
expect(res.statusCode).to.equal(200);
setTimeout(function() {
chai.request(server)
.post('/thisis/last_post')
.send()
.end((err, res) => {
expect(res.statusCode).to.equal(200);
done();
})
},20000);
});
});
});
});
Thanks.