在替换不赞成使用的函数调用时,我遇到了这个问题:
/// This function is deprecated because it doesn't work well with strong mode.
/// Use [expectAsync0], [expectAsync1],
/// [expectAsync2], [expectAsync3], [expectAsync4], [expectAsync5], or
/// [expectAsync6] instead.
@Deprecated("Will be removed in 0.13.0")
Function expectAsync(Function callback,
{int count: 1, int max: 0, String id, String reason}) {
if (Invoker.current == null) {
throw new StateError("expectAsync() may only be called within a test.");
}
return new _ExpectedFunction(callback, count, max, id: id, reason: reason)
.func;
}
它是
的一部分〜/ .pub-cache / hosted / pub.dartlang.org / test-0.12.37 / lib / src / frontend / expect_async.dart
什么是[expectAsync0],[expectAsync1],[expectAsync2],[expectAsync3],[expectAsync4],[expectAsync5]或[expectAsync6]?
如何使用它们?
答案 0 :(得分:0)
这些只是对方法expectAsync0
,expectAsync1
等的引用。
我想,方括号[...]等效于JavaDoc @link
,这意味着在创建该方法的文档时,对其他方法的引用是可以单击的链接。
另请参阅以下dart doc guidelines:
Links Normal URI hyperlinks are supported, as well as automatic links to Dart identifiers. Identifier [id] or [id](uri) Both generate a hyperlink to a Dart identifier. This identifier can be a class, method, or property.
答案 1 :(得分:0)
在单元测试中调用expectAsyncX(fun)
时(其中X是Arity,期望参数fun
的数量)
然后,测试将在测试超时后等待fun
被调用或因错误而失败。
这有时对测试异步代码很有帮助。例如,您可以使用它来等待事件处理程序被调用。在模拟事件处理程序中,您将调用fun()
通知测试发生了预期的行为。
由于异步匹配器已添加到test
包中,因此我认为这些功能的使用频率较低。
如果您实际上是指文档注释中的方括号,则它们允许引用导入的标识符,并允许在IDE中使用Ctrl + Click导航到声明,并在dartdoc
生成的HTML输出中将其呈现为超链接。