OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library unittest.test.utils; | 5 library unittest.test.utils; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:unittest/src/live_test.dart'; | 10 import 'package:unittest/src/live_test.dart'; |
| 11 import 'package:unittest/src/load_exception.dart'; |
11 import 'package:unittest/src/remote_exception.dart'; | 12 import 'package:unittest/src/remote_exception.dart'; |
12 import 'package:unittest/src/state.dart'; | 13 import 'package:unittest/src/state.dart'; |
13 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
14 | 15 |
15 // The last state change detected via [expectStates]. | 16 // The last state change detected via [expectStates]. |
16 State lastState; | 17 State lastState; |
17 | 18 |
18 /// Asserts that exactly [states] will be emitted via [liveTest.onStateChange]. | 19 /// Asserts that exactly [states] will be emitted via [liveTest.onStateChange]. |
19 /// | 20 /// |
20 /// The most recent emitted state is stored in [_lastState]. | 21 /// The most recent emitted state is stored in [_lastState]. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 /// Returns a matcher that matches a [TestFailure] with the given [message]. | 65 /// Returns a matcher that matches a [TestFailure] with the given [message]. |
65 Matcher isTestFailure(String message) => predicate( | 66 Matcher isTestFailure(String message) => predicate( |
66 (error) => error is TestFailure && error.message == message, | 67 (error) => error is TestFailure && error.message == message, |
67 'is a TestFailure with message "$message"'); | 68 'is a TestFailure with message "$message"'); |
68 | 69 |
69 /// Returns a matcher that matches a [RemoteException] with the given [message]. | 70 /// Returns a matcher that matches a [RemoteException] with the given [message]. |
70 Matcher isRemoteException(String message) => predicate( | 71 Matcher isRemoteException(String message) => predicate( |
71 (error) => error is RemoteException && error.message == message, | 72 (error) => error is RemoteException && error.message == message, |
72 'is a RemoteException with message "$message"'); | 73 'is a RemoteException with message "$message"'); |
73 | 74 |
| 75 /// Returns a matcher that matches a [LoadException] with the given [message]. |
| 76 Matcher isLoadException(String message) => predicate( |
| 77 (error) => error is LoadException && error.innerError == message, |
| 78 'is a LoadException with message "$message"'); |
| 79 |
74 /// Returns a [Future] that completes after pumping the event queue [times] | 80 /// Returns a [Future] that completes after pumping the event queue [times] |
75 /// times. | 81 /// times. |
76 /// | 82 /// |
77 /// By default, this should pump the event queue enough times to allow any code | 83 /// By default, this should pump the event queue enough times to allow any code |
78 /// to run, as long as it's not waiting on some external event. | 84 /// to run, as long as it's not waiting on some external event. |
79 Future pumpEventQueue([int times=20]) { | 85 Future pumpEventQueue([int times=20]) { |
80 if (times == 0) return new Future.value(); | 86 if (times == 0) return new Future.value(); |
81 // Use [new Future] future to allow microtask events to finish. The [new | 87 // Use [new Future] future to allow microtask events to finish. The [new |
82 // Future.value] constructor uses scheduleMicrotask itself and would therefore | 88 // Future.value] constructor uses scheduleMicrotask itself and would therefore |
83 // not wait for microtask callbacks that are scheduled after invoking this | 89 // not wait for microtask callbacks that are scheduled after invoking this |
84 // method. | 90 // method. |
85 return new Future(() => pumpEventQueue(times - 1)); | 91 return new Future(() => pumpEventQueue(times - 1)); |
86 } | 92 } |
OLD | NEW |