摩卡如何知道已指定完成? [英] How does Mocha know that done was specified?
本文介绍了摩卡如何知道已指定完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我使用Mocha编写异步测试,我要做的就是在测试函数上指定完成的参数:
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) {...});
我的问题是:摩卡咖啡如何知道是否已完成?
My question is: How does Mocha know whether done was given?
测试函数的定义应为
function test(title, fn) {...};
摩卡咖啡如何检查fn?
How does Mocha check fn?
推荐答案
它在测试函数上使用.length
属性.
It uses the .length
property on the test function.
为说明起见,请在Node REPL中尝试以下操作:
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;
这篇关于摩卡如何知道已指定完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文