How does Mocha know that done was specified?

后端 未结 1 1667
天命终不由人
天命终不由人 2021-01-19 13:37

If I write an asynchronous test using Mocha, all I need to do is to specify the done parameter on the test function:

test(\'foo\', function (done) {...});


        
相关标签:
1条回答
  • 2021-01-19 14:26

    It uses the .length property on the test function.

    To illustrate, try this in the Node REPL:

    > (function() {}).length
    0
    > (function(done) {}).length
    1
    

    Here's the actual line in the source where this check happens:

    this.async = fn && fn.length;
    
    0 讨论(0)
提交回复
热议问题