作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我真的不明白protectAsyncN方法的目的。
有人可以告诉我它应该如何工作吗?例如,假设以下测试用例:
import "package:unittest/unittest.dart";
import "dart:async";
void main() {
test("Protect async", () {
// given
var controller = new StreamController();
// when
controller.add("This is correct!");
// then
controller.stream.listen(protectAsync1((event) {
expect(event, equals("This is correct!"));
}));
});
}
unittest-suite-wait-for-done
ERROR: Protect async
Callback called (1) after test case Protect async has already been marked as pass.
0 PASSED, 0 FAILED, 1 ERRORS
Unhandled exception:
Exception: Some tests failed.
#0 SimpleConfiguration.onDone (package:unittest/src/simple_configuration.dart:213:9)
#1 _completeTests (package:unittest/unittest.dart:779:17)
#2 _runTest (package:unittest/unittest.dart:734:19)
#3 _nextTestCase (package:unittest/unittest.dart:641:11)
#4 _asyncRunCallback (dart:async/schedule_microtask.dart:18)
#5 _asyncRunCallback (dart:async/schedule_microtask.dart:21)
#6 _createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:11)
#7 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:151)
#8 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:159)
#9 _Timer._createTimerHandler._handleTimeout (timer_impl.dart:159)
#10 _Timer._createTimerHandler.<anonymous closure> (timer_impl.dart:166)
#11 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:93)
最佳答案
在these docs中被描述为
Wraps the callback in a new function and returns that function. The new function will be able to handle exceptions by directing them to the correct test. This is thus similar to expectAsync0. Use it to wrap any callbacks that might optionally be called but may never be called during the test. callback should take 0 positional arguments (named arguments are not supported). id can be used to identify the callback in error messages (for example if it is called after the test case is complete).
关于dart - Dart单元测试包中的protectAsyncN如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19958625/
我是一名优秀的程序员,十分优秀!