【发布时间】:2016-08-25 14:01:29
【问题描述】:
这个问题是这个问题的简化版:Testing dart ajax HttpRequest
我基本上删除了所有不必要的代码,只留下了测试和HttpRequest.postFormData 调用。
问题:测试似乎没有等到 Future 完成。 测试代码:
# http_report_adapter_test.dart
import "package:test/test.dart";
import 'dart:html';
void main() {
test("sends an ajax request and acknowledges a 200 response from the server", () {
var f = HttpRequest.postFormData("http://localhost:4567/errors", { 'hello': 'world'});
f.then((_) => print("!!!!!!!"));
return f;
});
}
根据建议,我 return f 并且测试应该等到 Future 完成。但是,这是我得到的输出:
~/Work/my_libs/dart/logmaster master$ dtest-d -n "sends an ajax request and acknowledges a 200 response from the server"
00:05 +0 -1: test/http_report_adapter_test.dart: sends an ajax request and acknowledges a 200 response from the server
[object XMLHttpRequestProgressEvent]
dart:html HttpRequest.postFormData
http_report_adapter_test.dart 14:25 main.<fn>
[object XMLHttpRequestProgressEvent]
dart:html HttpRequest.postFormData
http_report_adapter_test.dart 14:25 main.<fn>
我想我显然误解了一些基本的东西。我已经尝试了这个测试的多种变体,async/await、expectAsync、completion,但似乎没有任何效果。希望有任何好的建议。
【问题讨论】:
标签: ajax dart async-await dart-async