Index: pkg/observe/test/observe_test_utils.dart |
diff --git a/pkg/observe/test/observe_test_utils.dart b/pkg/observe/test/observe_test_utils.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6115657ba355e5d728a7901c9dc757e17557a7aa |
--- /dev/null |
+++ b/pkg/observe/test/observe_test_utils.dart |
@@ -0,0 +1,51 @@ |
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+library observe.test.observe_test_utils; |
+ |
+import 'dart:async'; |
+import 'package:observe/observe.dart'; |
+import 'package:unittest/unittest.dart'; |
+ |
+// TODO(jmesserly): use matchers when we have a way to compare ChangeRecords. |
+// For now just use the toString. |
+expectChanges(actual, expected, {reason}) => |
+ expect('$actual', '$expected', reason: reason); |
+ |
+void performMicrotaskCheckpoint() { |
+ Observable.dirtyCheck(); |
+ |
+ while (_pending.length > 0) { |
+ var pending = _pending; |
+ _pending = []; |
+ |
+ for (var callback in pending) { |
+ try { |
+ callback(); |
+ } catch (e, s) { |
+ new Completer().completeError(e, s); |
+ } |
+ } |
+ |
+ Observable.dirtyCheck(); |
+ } |
+} |
+ |
+List<Function> _pending = []; |
+ |
+wrapMicrotask(void testCase()) { |
+ return () { |
+ runZonedExperimental(() { |
+ try { |
+ testCase(); |
+ } finally { |
+ performMicrotaskCheckpoint(); |
+ } |
+ }, onRunAsync: (callback) => _pending.add(callback)); |
+ }; |
+} |
+ |
+observeTest(name, testCase) => test(name, wrapMicrotask(testCase)); |
+ |
+solo_observeTest(name, testCase) => solo_test(name, wrapMicrotask(testCase)); |