For some reason I am getting a mocha timeout although the response returns with 202 success... I have several other tests that are written in the exact same fashion and there is no timeout:
describe('PUT /api/editTenant', function() {
it('it should change an existing tenant', function(done) {
should.exist(test_tenant.tenant_id);
var body = {
email : "test@example.com",
message: "Hello!",
tenant_id : test_tenant._id,
searchOpts : {}
};
request(host).put('/api/edit').send(body).end(function(err, res) {
if(err) throw err;
res.should.have.status(202);
done();
});
});
});
And here is the code being tested:
exports.editTenant = function(req, res) {
Tenant.findOneAndUpdate({ _id : tenant.tenant_id }, {
email : req.body.email,
phone : req.body.phone,
searchOpts : req.body.searchOpts,
contactMessage : req.body.message
}, function(err, affected) {
if(err) res.json(401, err);
res.json(202, { updated : affected } );
});
};
Again I have several tests just like this and there is no timeout... Is the problem that I'm doing a put not a post?
you should set the timeout of the mocha
this.timeout(20000); // 20seconds you can have any value
example:you can change your code like
describe('PUT /api/editTenant', function() {
it('it should change an existing tenant', function(done) {
this.timeout(20000); // add this code
should.exist(test_tenant.tenant_id);