OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library async.test.async_thunk_test; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:async/async.dart'; |
| 10 import 'package:test/test.dart'; |
| 11 |
| 12 main() { |
| 13 var thunk; |
| 14 setUp(() => thunk = new AsyncThunk()); |
| 15 |
| 16 test("runs the function only the first time run() is called", () async { |
| 17 var count = 0; |
| 18 await thunk.run(() => count++); |
| 19 expect(count, equals(1)); |
| 20 |
| 21 await thunk.run(() => count++); |
| 22 expect(count, equals(1)); |
| 23 }); |
| 24 |
| 25 test("forwards the return value from the function", () async { |
| 26 expect(thunk.run(() => "value"), completion(equals("value"))); |
| 27 expect(thunk.run(() {}), completion(equals("value"))); |
| 28 }); |
| 29 |
| 30 test("forwards the error from the function", () async { |
| 31 expect(thunk.run(() => throw "error"), throwsA("error")); |
| 32 expect(thunk.run(() {}), throwsA("error")); |
| 33 }); |
| 34 } |
OLD | NEW |