Recently I was updating and fixing some existing unit tests after doing a (rather large) overhaul of code.
The unit test previously needed to wait for an asynchronous callback to finish before continuing, something like this:
Note the optional done parameter provided to beforeEach. This is a void function that signals Jasmine that the callback is finished. Jasmine will wait for done() to be called before continuing execution of your test.
Error
If you don’t call done(), you will be met with an unhelpful error message:
Error: Timeout – Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Fix
You can fix this by either:
- calling done()
- removing the done parameter from your function (if, like in my case, you no longer are waiting for an async call).