For each lab, the JavaScript test framework is allotted a certain amount of time in which to run the tests. This error occurs when the tests do not finish running within that amount of time.
This error may indicate that something is wrong with your code.
First, if you are in a lab that involves Javascript Promises, make sure that you are resolving them correctly.
For example (see above), if you had return questions
instead of resolve(questions)
by mistake, you would get this error:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves
To fix this, simply fix the code to correctly resolve the Promise.
You've fixed the code and/or your error looks more like this one, below. Now what?
1) "before all" hook:
Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
If this is the case, follow these steps:
- Open the
package.json
file in the directory for your lab. - Locate the
"scripts"
key, and the"test"
key within"scripts"
- After
mocha
, add--timeout 5000
so that the key looks like this:"scripts": { "test": "mocha --timeout 5000 -R mocha-multi --reporter-options nyan=-,json=.results.json" }
,
Increase the number in step 3 by 5000 and run the tests again until this error no longer occurs.