OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012, 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.future_matchers_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 expectTestResults('group name test', () { | |
18 test('completes - unexpected error', () { | |
19 var completer = new Completer(); | |
20 completer.completeError('X'); | |
21 expect(completer.future, completes); | |
22 }); | |
23 | |
24 test('completes - successfully', () { | |
25 var completer = new Completer(); | |
26 completer.complete('1'); | |
27 expect(completer.future, completes); | |
28 }); | |
29 | |
30 test('throws - unexpected to see normal completion', () { | |
31 var completer = new Completer(); | |
32 completer.complete('1'); | |
33 expect(completer.future, throws); | |
34 }); | |
35 | |
36 test('throws - expected to see exception', () { | |
37 var completer = new Completer(); | |
38 completer.completeError('X'); | |
39 expect(completer.future, throws); | |
40 }); | |
41 | |
42 test('throws - expected to see exception thrown later on', () { | |
43 var completer = new Completer(); | |
44 var chained = completer.future.then((_) { | |
45 throw 'X'; | |
46 }); | |
47 expect(chained, throws); | |
48 completer.complete('1'); | |
49 }); | |
50 | |
51 test('throwsA - unexpected normal completion', () { | |
52 var completer = new Completer(); | |
53 completer.complete('1'); | |
54 expect(completer.future, throwsA(equals('X'))); | |
55 }); | |
56 | |
57 test('throwsA - correct error', () { | |
58 var completer = new Completer(); | |
59 completer.completeError('X'); | |
60 expect(completer.future, throwsA(equals('X'))); | |
61 }); | |
62 | |
63 test('throwsA - wrong error', () { | |
64 var completer = new Completer(); | |
65 completer.completeError('X'); | |
66 expect(completer.future, throwsA(equals('Y'))); | |
67 }); | |
68 }, [ | |
69 { | |
70 'result': 'fail', | |
71 'message': 'Expected future to complete successfully, but it failed with ' | |
72 'X', | |
73 }, | |
74 {'result': 'pass'}, | |
75 { | |
76 'result': 'fail', | |
77 'message': 'Expected future to fail, but succeeded with \'1\'.' | |
78 }, | |
79 {'result': 'pass'}, | |
80 {'result': 'pass'}, | |
81 { | |
82 'result': 'fail', | |
83 'message': 'Expected future to fail, but succeeded with \'1\'.' | |
84 }, | |
85 {'result': 'pass'}, | |
86 { | |
87 'result': 'fail', | |
88 'message': '''Expected: 'Y' | |
89 Actual: 'X' | |
90 Which: is different. | |
91 Expected: Y | |
92 Actual: X | |
93 ^ | |
94 Differ at offset 0 | |
95 ''' | |
96 } | |
97 ]); | |
98 } | |
OLD | NEW |