在suback / tape中使用“plan”和“end”的目的是什么?
substack的磁带testing模块允许您使用plan
方法提前指定断言的数量,然后它会自动为您调用end
。 为什么不把testing结束呢? 使用plan
和end
什么区别?
自述文件中的第一个示例显示了plan
工作但end
不会执行asynchronoustesting解决的情况。 在这种情况下,你没有明确说明testing什么时候应该都已经解决了,而是说有多less应该最终解决:
test('timing test', function (t) { t.plan(2); t.equal(typeof Date.now, 'function'); var start = Date.now(); setTimeout(function () { t.equal(Date.now() - start, 100); }, 100); });
如果我们使用end
的方法,那么编写这个testing的直观方法如下:
test('timing test', function (t) { t.equal(typeof Date.now, 'function'); var start = Date.now(); setTimeout(function () { t.equal(Date.now() - start, 100); }, 100); t.end(); });
…但是这将在第二个断言有机会运行之前结束testing。
您可以进一步推断出任何需要执行asynchronous或dynamic代码的情况。