OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library unittest.test.utils; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:unittest/unittest.dart'; |
| 10 |
| 11 /// Returns a matcher that matches a [TestFailure] with the given [message]. |
| 12 Matcher isTestFailure(String message) => predicate( |
| 13 (error) => error is TestFailure && error.message == message, |
| 14 'is a TestFailure with message "$message"'); |
| 15 |
| 16 /// Returns a [Future] that completes after pumping the event queue [times] |
| 17 /// times. |
| 18 /// |
| 19 /// By default, this should pump the event queue enough times to allow any code |
| 20 /// to run, as long as it's not waiting on some external event. |
| 21 Future pumpEventQueue([int times=20]) { |
| 22 if (times == 0) return new Future.value(); |
| 23 // Use [new Future] future to allow microtask events to finish. The [new |
| 24 // Future.value] constructor uses scheduleMicrotask itself and would therefore |
| 25 // not wait for microtask callbacks that are scheduled after invoking this |
| 26 // method. |
| 27 return new Future(() => pumpEventQueue(times - 1)); |
| 28 } |
OLD | NEW |