Mocha: Error Timeout of 2000ms exceeded

Because (done) will actually return the function instead of invoking it. In order to call done, you need to write it this way.

.then(() => done())

However, I don't recommend using done along with promises. You just simply need to return the promise then mocha will handle it automatically.

const saveUsersToDB = () => db.User.bulkCreate(users)

By default, Mocha tests have a 2 second timeout (which means that the test needs to be completed in 2 seconds).

You can increase it (in milliseconds) as follows:

this.timeout(5000); // this test can take up to 5 seconds

https://mochajs.org/#timeouts


I had the same isue. This error promps because the 2 seconds timeout, so if your test needs to connect to ddbb it will most provably surpas it.

What I did was to separate all my tests that needed somme kind of connection to external resources into my integration tests folder and then added the next flag in my package.json test script:

"int-test": "mocha --timeout 15000 tests/integration/**/*.test.js --compilers js:babel-register "

Follow this link for other ways to increase the timeout: mocha timout