mocha: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
I’m getting the following error when running the entire suite of tests:
timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
I found this super useful response on StackOverflow http://stackoverflow.com/questions/16607039/in-mocha-testing-while-calling-asynchronous-function-how-to-avoid-the-timeout-er# and here https://github.com/mochajs/mocha/pull/278
However, the problem still persists even after deleting every occurrence in my tests that deal with HTTP and promises. All I’ve got now are Angular directive and controller specs which doesn’t seem to do much other than checking template data, directive and controller logic.
Does anyone know why this is still happening and if there’s a better way to know exactly what the issue is? thanks!
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 46
- Comments: 24 (3 by maintainers)
Commits related to this issue
- Modify npm test script to allow for longer timeout This change fixes the timeout error that was occuring upon testing which was causing tests to fail. For further reference, see: https://github.com/... — committed to greatwillow/react-datasheet by greatwillow 6 years ago
- Add timeout for test It seems the first test is having issues with a timeout. Added timeout as recommended by https://github.com/mochajs/mocha/issues/2025 — committed to Confidenceman02/elm-select by deleted user 3 years ago
- Add timeout for test It seems the first test is having issues with a timeout. Added timeout as recommended by https://github.com/mochajs/mocha/issues/2025 — committed to Confidenceman02/elm-select by deleted user 3 years ago
- Add timeout for test It seems the first test is having issues with a timeout. Added timeout as recommended by https://github.com/mochajs/mocha/issues/2025 — committed to Confidenceman02/elm-select by deleted user 3 years ago
- Add timeout for test It seems the first test is having issues with a timeout. Added timeout to test script as recommended by https://github.com/mochajs/mocha/issues/2025 — committed to Confidenceman02/elm-select by deleted user 3 years ago
- Augmentation du timeout pour résoudre la pipeline failed (https://github.com/mochajs/mocha/issues/2025) — committed to robin-76/web-tp2 by okaberin76 3 years ago
just add in your package.json under scripts
Then you can just run
Test-specific timeouts may also be applied, or the use of this.timeout(0) to disable timeouts all together:
source: https://mochajs.org/#timeouts
@ScottFreeCode thank you. Error resolved by adding this.timeout(10000); inside
Am getting Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure “done()” is called; if returning a Promise, ensure it resolves. How to fix this? My code is:
I was also getting that error, and after several hours of researching and debugging, I found the root cause.
Consider this test:
When I run the test, I get this error:
Now consider this slightly different test, where the done argument is removed:
When I run this test, it passes.
Somehow the presence of the done argument in the async function breaks the test, even if it’s not used, and even if done() is called at the end of the test.
Closing this issue. It turned out to be a memory leak issue described here https://github.com/mochajs/mocha/issues/2030
Hi @vishnu2prasadh, have you tried increasing the timeout to longer than the HTTP API is expected to take to respond? Your test’s usage of
done
appears to be correct.Adding --timeout 10000 to the the “test” “scripts” , worked like charm to me. Thank you!
I resolved this my creating a global timeout rather than setting it for individual tests or adding the configuration to my
package.json
file. Under my test folder I created a filemocha.opts
. In the file, I set a reasonable timeout span for my tests to run, e.g.,--timeout 10000
the most useful answer so far 👍