OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, 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 unittest.expect_async_test; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:metatest/metatest.dart'; |
| 10 import 'package:unittest/unittest.dart'; |
| 11 |
| 12 void main() => initTests(_test); |
| 13 |
| 14 void _test(message) { |
| 15 initMetatest(message); |
| 16 |
| 17 var count = 0; |
| 18 |
| 19 expectTestsPass('expect async test', () { |
| 20 test('expectAsync zero params', () { |
| 21 new Future.sync(expectAsync(() { |
| 22 ++count; |
| 23 })); |
| 24 }); |
| 25 |
| 26 test('expectAsync 1 param', () { |
| 27 var func = expectAsync((arg) { |
| 28 expect(arg, 0); |
| 29 ++count; |
| 30 }); |
| 31 new Future.sync(() => func(0)); |
| 32 }); |
| 33 |
| 34 test('expectAsync 2 param', () { |
| 35 var func = expectAsync((arg0, arg1) { |
| 36 expect(arg0, 0); |
| 37 expect(arg1, 1); |
| 38 ++count; |
| 39 }); |
| 40 new Future.sync(() => func(0, 1)); |
| 41 }); |
| 42 |
| 43 test('single arg to Future.catchError', () { |
| 44 var func = expectAsync((error) { |
| 45 expect(error, isStateError); |
| 46 ++count; |
| 47 }); |
| 48 |
| 49 new Future(() { |
| 50 throw new StateError('test'); |
| 51 }).catchError(func); |
| 52 }); |
| 53 |
| 54 test('2 args to Future.catchError', () { |
| 55 var func = expectAsync((error, stack) { |
| 56 expect(error, isStateError); |
| 57 expect(stack is StackTrace, isTrue); |
| 58 ++count; |
| 59 }); |
| 60 |
| 61 new Future(() { |
| 62 throw new StateError('test'); |
| 63 }).catchError(func); |
| 64 }); |
| 65 |
| 66 test('zero of two optional positional args', () { |
| 67 var func = expectAsync(([arg0 = true, arg1 = true]) { |
| 68 expect(arg0, isTrue); |
| 69 expect(arg1, isTrue); |
| 70 ++count; |
| 71 }); |
| 72 |
| 73 new Future.sync(() => func()); |
| 74 }); |
| 75 |
| 76 test('one of two optional positional args', () { |
| 77 var func = expectAsync(([arg0 = true, arg1 = true]) { |
| 78 expect(arg0, isFalse); |
| 79 expect(arg1, isTrue); |
| 80 ++count; |
| 81 }); |
| 82 |
| 83 new Future.sync(() => func(false)); |
| 84 }); |
| 85 |
| 86 test('two of two optional positional args', () { |
| 87 var func = expectAsync(([arg0 = true, arg1 = true]) { |
| 88 expect(arg0, isFalse); |
| 89 expect(arg1, isNull); |
| 90 ++count; |
| 91 }); |
| 92 |
| 93 new Future.sync(() => func(false, null)); |
| 94 }); |
| 95 |
| 96 test('verify count', () { |
| 97 expect(count, 8); |
| 98 }); |
| 99 }); |
| 100 } |
OLD | NEW |