OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, 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 observe.test.observe_test_utils; |
| 6 |
| 7 import 'dart:async'; |
| 8 import 'package:observe/observe.dart'; |
| 9 import 'package:unittest/unittest.dart'; |
| 10 |
| 11 // TODO(jmesserly): use matchers when we have a way to compare ChangeRecords. |
| 12 // For now just use the toString. |
| 13 expectChanges(actual, expected, {reason}) => |
| 14 expect('$actual', '$expected', reason: reason); |
| 15 |
| 16 void performMicrotaskCheckpoint() { |
| 17 Observable.dirtyCheck(); |
| 18 |
| 19 while (_pending.length > 0) { |
| 20 var pending = _pending; |
| 21 _pending = []; |
| 22 |
| 23 for (var callback in pending) { |
| 24 try { |
| 25 callback(); |
| 26 } catch (e, s) { |
| 27 new Completer().completeError(e, s); |
| 28 } |
| 29 } |
| 30 |
| 31 Observable.dirtyCheck(); |
| 32 } |
| 33 } |
| 34 |
| 35 List<Function> _pending = []; |
| 36 |
| 37 wrapMicrotask(void testCase()) { |
| 38 return () { |
| 39 runZonedExperimental(() { |
| 40 try { |
| 41 testCase(); |
| 42 } finally { |
| 43 performMicrotaskCheckpoint(); |
| 44 } |
| 45 }, onRunAsync: (callback) => _pending.add(callback)); |
| 46 }; |
| 47 } |
| 48 |
| 49 observeTest(name, testCase) => test(name, wrapMicrotask(testCase)); |
| 50 |
| 51 solo_observeTest(name, testCase) => solo_test(name, wrapMicrotask(testCase)); |
OLD | NEW |