According to Mocha documentation, "Mocha tests run serially" which means in the order they are defined.
My question is: what makes async (with done callback) tests different than sync?
According to Mocha documentation, "Mocha tests run serially" which means in the order they are defined.
My question is: what makes async (with done callback) tests different than sync?
You tell Mocha that a test is asynchronous by passing to the
it
call a function that takes an argument (traditionally nameddone
). Mocha will then call this function with a first argument which is a callback that you must call to tell Mocha the test is over.The only difference between an asynchronous test and a synchronous one is that for an asynchronous test Mocha will wait for the
done
callback to be called before moving on to the next test. If the test is deemed to be synchronous, then Mocha will move on to the next test as soon as the function you passed toit
returns. If Mocha were to do this with asynchronous tests too then it would not be able to associate unhandled exceptions with the appropriate test.