1

I always get this error

Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

idk what's wrong with mocha tests hope someone helps (the post client works tho)

controller.js

module.exports.get_post_tags = (req, res) => {
  PostTag.find({})
  .then(tags => res.json(tags))
  .catch(err => {
    console.error(err)
    res.send('An error happened while getting the data please try again later')
  })
}

api.js

// @method GET
// @route /api/posttag
// @desc get all post tags
router.get('/posttags', get_post_tags)

unit_tests.js

describe('PostTag', function() {
    it('Get all post tags', function(done) {
      chai.request(app)
        .get('/api/posttags')
        .end((err, res) => {
          expect(res).to.have.status(200)
          done()
        });
    });
}
  • I also have this problem, no clue whatsoever, found some answer saying I should change mocha timeout to 10 seconds for example, but I don't think that solves the problem of why are the tests taking too much time :/ – aelmosalamy Jul 10 '20 at 14:33
  • Did you try to increase the timeout ? You can check this https://stackoverflow.com/q/15971167/10104078 – Noahfaita Jul 10 '20 at 14:33
  • I don't know about OP, but it indeed works when the timeout is increased; however, this is more of a hack rather than a proper solution. – aelmosalamy Jul 10 '20 at 14:45

0 Answers0