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 matcher.future_matchers_test; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 import 'package:matcher/matcher.dart'; | |
10 import 'package:unittest/unittest.dart' show test, group; | |
11 | |
12 import 'test_utils.dart'; | |
13 | |
14 void main() { | |
15 initUtils(); | |
16 | |
17 test('completes - unexpected error', () { | |
18 var completer = new Completer(); | |
19 completer.completeError('X'); | |
20 shouldFail(completer.future, completes, contains( | |
21 'Expected future to complete successfully, ' | |
22 'but it failed with X'), isAsync: true); | |
23 }); | |
24 | |
25 test('completes - successfully', () { | |
26 var completer = new Completer(); | |
27 completer.complete('1'); | |
28 shouldPass(completer.future, completes, isAsync: true); | |
29 }); | |
30 | |
31 test('throws - unexpected to see normal completion', () { | |
32 var completer = new Completer(); | |
33 completer.complete('1'); | |
34 shouldFail(completer.future, throws, | |
35 contains("Expected future to fail, but succeeded with '1'"), | |
36 isAsync: true); | |
37 }); | |
38 | |
39 test('throws - expected to see exception', () { | |
40 var completer = new Completer(); | |
41 completer.completeError('X'); | |
42 shouldPass(completer.future, throws, isAsync: true); | |
43 }); | |
44 | |
45 test('throws - expected to see exception thrown later on', () { | |
46 var completer = new Completer(); | |
47 var chained = completer.future.then((_) { | |
48 throw 'X'; | |
49 }); | |
50 shouldPass(chained, throws, isAsync: true); | |
51 completer.complete('1'); | |
52 }); | |
53 | |
54 test('throwsA - unexpected normal completion', () { | |
55 var completer = new Completer(); | |
56 completer.complete('1'); | |
57 shouldFail(completer.future, throwsA(equals('X')), | |
58 contains("Expected future to fail, but succeeded with '1'"), | |
59 isAsync: true); | |
60 }); | |
61 | |
62 test('throwsA - correct error', () { | |
63 var completer = new Completer(); | |
64 completer.completeError('X'); | |
65 shouldPass(completer.future, throwsA(equals('X')), isAsync: true); | |
66 }); | |
67 | |
68 test('throwsA - wrong error', () { | |
69 var completer = new Completer(); | |
70 completer.completeError('X'); | |
71 shouldFail(completer.future, throwsA(equals('Y')), | |
72 "Expected: 'Y' Actual: 'X' " | |
73 "Which: is different. " | |
74 "Expected: Y Actual: X ^ Differ at offset 0", isAsync: true); | |
75 }); | |
76 } | |
OLD | NEW |