-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
timeout of 2000ms exceeded. Ensure the done() callback is being called in this test. #2025
Comments
@gumatias to be much more help we'd need to set your tests |
thanks for the feedback @boneskull ! There's around 700+ specs at the moment and they're all proprietary code. I can provide one of two similar samples, would that be any helpful? |
Below is what I currently have in package.json. Upgrading libraries such as mocha and karma-mocha didn't seem to help.
Below are some of my attempts on getting to a state where the timeouts would stop occurring (without success). 1. Called 2. Removed all specs that deals with async calls, promises, httpBackend and timeout (just in case) 3. Upgraded most libraries in
4. Removed specs that karma spec reporter was complaining to be slow: Turned out other new specs were complaining to be slow. This could probably lead to deleting specs without really finding the root cause. |
Closing this issue. It turned out to be a memory leak issue described here #2030 |
Test-specific timeouts may also be applied, or the use of this.timeout(0) to disable timeouts all together:
source: https://mochajs.org/#timeouts |
If you're using Ember, try wrapping async calls in Ember.run => read this I had the same problem, and Ember.run => fixed it. Also, remember the arrow has to be a fat arrow, (i made that mistake once of using -> instead of =>)it's because of javascript scope, read up on it if you are interested. |
Am getting
|
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 |
@ScottFreeCode thank you. Error resolved by adding this.timeout(10000); inside
|
just add in your package.json under scripts
Then you can just run
|
@elvinaze is there a way to increase timeout limits in the beforeEach block? |
This change fixes the timeout error that was occuring upon testing which was causing tests to fail. For further reference, see: mochajs/mocha#2025
the most useful answer so far 👍 |
still for me why .Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves |
it('should access user module', function(done){ var any_asynchfunction = function (){ Testing async code with Mocha using callbacks and promises |
@ashish101184, don't add comments to unrelated closed issues! Your problem was explained in the documentation. it('should access user module', function() {
return any_asynchfunction()
.then(function(check) {
assert.strictEqual(check, true, 'admin user should have access to user module');
});
}); |
|
I resolved this my creating a global timeout rather than setting it for individual tests or adding the configuration to my
|
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. |
Adding --timeout 10000 to the the "test" "scripts" , worked like charm to me. |
I know this is old, but I have encountered tests that run fine on one version of Node, but hang with the "timeout of 2000ms exceeded. Ensure the done() callback" message on other versions. My node code runs on Node v 14.x as per my Dockerfile, and my tests pass fine on that version. But on a build agent in Azure, I was running on Node v 12.x, and I was getting this error. Once I specified v 14.x, it also worked on Azure's pipeline without any other code changes. 👍 So it's worth trying a few different versions of Node, if you're otherwise stuck! Thanks to all who have previously commented on this issue. Good info to know. |
It seems the first test is having issues with a timeout. Added timeout as recommended by mochajs/mocha#2025
It seems the first test is having issues with a timeout. Added timeout as recommended by mochajs/mocha#2025
It seems the first test is having issues with a timeout. Added timeout as recommended by mochajs/mocha#2025
It seems the first test is having issues with a timeout. Added timeout to test script as recommended by mochajs/mocha#2025
i solved mine by adding "done()" after the .end closing bracket .end((err, res) => { |
Gracias Iroh-Omolola !!! a mi me funcionó perfecto con tu resolución |
no |
no |
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 #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!
The text was updated successfully, but these errors were encountered: