尝试测试异步Dart ajax HttpRequest时出错

时间:2016-04-30 12:09:47

标签: ajax dart async-await dart-async

这个问题是这个问题的简化版本:Testing dart ajax HttpRequest

我基本上删除了所有不必要的代码,只留下了测试和wordLetterSelect = [ { id: 'A', name: 'A' }, { id: 'B', name: 'B' } ]; 调用。

问题:测试似乎不等到Future完成。 测试代码:

HttpRequest.postFormData

根据建议,我# 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; }); } 并且测试应该等到Future完成。但是,这是我得到的输出:

return f

我认为我显然误解了一些基本的东西。我已尝试使用~/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/awaitexpectAsync进行此测试的多种变体,但似乎没有任何效果。非常感谢任何好的建议。

1 个答案:

答案 0 :(得分:1)

我认为你想要的是:

  test("sends an ajax request and acknowledges a 200 response from the server", () async {
    await HttpRequest.postFormData("http://localhost:4567/errors", { 'hello': 'world'});

    print("hello!"); // or expect(x, y);
  });