Index: test/async_thunk_test.dart |
diff --git a/test/async_thunk_test.dart b/test/async_thunk_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d4a1f4fe6605745d618ca3de4b3012513b07bfb9 |
--- /dev/null |
+++ b/test/async_thunk_test.dart |
@@ -0,0 +1,34 @@ |
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+library async.test.async_thunk_test; |
+ |
+import 'dart:async'; |
+ |
+import 'package:async/async.dart'; |
+import 'package:test/test.dart'; |
+ |
+main() { |
+ var thunk; |
+ setUp(() => thunk = new AsyncThunk()); |
+ |
+ test("runs the function only the first time run() is called", () async { |
+ var count = 0; |
+ await thunk.run(() => count++); |
+ expect(count, equals(1)); |
+ |
+ await thunk.run(() => count++); |
+ expect(count, equals(1)); |
+ }); |
+ |
+ test("forwards the return value from the function", () async { |
+ expect(thunk.run(() => "value"), completion(equals("value"))); |
+ expect(thunk.run(() {}), completion(equals("value"))); |
+ }); |
+ |
+ test("forwards the error from the function", () async { |
+ expect(thunk.run(() => throw "error"), throwsA("error")); |
+ expect(thunk.run(() {}), throwsA("error")); |
+ }); |
+} |