promise & mocha: done() in before or not?

前端 未结 3 1374
生来不讨喜
生来不讨喜 2021-01-19 23:42

I am reading some tutorials on promise tests in mocha. There is a piece of codes:

before(function(done) {
  return Promise.resolve(save(article)).then(functi         


        
3条回答
  •  隐瞒了意图╮
    2021-01-20 00:11

    In this particular case there is no functional difference. The callback, often called done, was introduced to handle asynchronous tests when using callbacks. Returning a Promise is sufficient, but note that you cannot define the done callback, because the test suite will wait until it's called. Use done when you can't easily return a Promise. In your case the second test will be infinite, because you define done, which you never actually call.

提交回复
热议问题