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