Mocha: async vs sync

2019-06-23 02:31发布

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?

标签: mocha
1条回答
\"骚年 ilove
2楼-- · 2019-06-23 03:07

You tell Mocha that a test is asynchronous by passing to the it call a function that takes an argument (traditionally named done). 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 to it 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.

查看更多
登录 后发表回答