| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 observe.test.observe_test_utils; | 5 /** |
| 6 * *Warning*: this library is **internal**, and APIs are subject to change. |
| 7 * |
| 8 * Wraps a callback using [wrapMicrotask] and provides the ability to pump all |
| 9 * observable objects and [runAsync] calls via [performMicrotaskCheckpoint]. |
| 10 */ |
| 11 library observe.src.microtask; |
| 6 | 12 |
| 7 import 'dart:async'; | 13 import 'dart:async' show Completer, runZonedExperimental; |
| 8 import 'package:observe/observe.dart'; | 14 import 'package:observe/observe.dart' show Observable; |
| 9 import 'package:unittest/unittest.dart'; | |
| 10 | 15 |
| 11 // TODO(jmesserly): use matchers when we have a way to compare ChangeRecords. | 16 // TODO(jmesserly): remove "microtask" from these names and instead import |
| 12 // For now just use the toString. | 17 // the library "as microtask"? |
| 13 expectChanges(actual, expected, {reason}) => | |
| 14 expect('$actual', '$expected', reason: reason); | |
| 15 | 18 |
| 16 /** | 19 /** |
| 17 * This change pumps events relevant to observers and data-binding tests. | 20 * This change pumps events relevant to observers and data-binding tests. |
| 18 * This must be used inside an [observeTest]. | 21 * This must be used inside an [observeTest]. |
| 19 * | 22 * |
| 20 * Executes all pending [runAsync] calls on the event loop, as well as | 23 * Executes all pending [runAsync] calls on the event loop, as well as |
| 21 * performing [Observable.dirtyCheck], until there are no more pending events. | 24 * performing [Observable.dirtyCheck], until there are no more pending events. |
| 22 * It will always dirty check at least once. | 25 * It will always dirty check at least once. |
| 23 */ | 26 */ |
| 24 void performMicrotaskCheckpoint() { | 27 void performMicrotaskCheckpoint() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 50 return () { | 53 return () { |
| 51 runZonedExperimental(() { | 54 runZonedExperimental(() { |
| 52 try { | 55 try { |
| 53 testCase(); | 56 testCase(); |
| 54 } finally { | 57 } finally { |
| 55 performMicrotaskCheckpoint(); | 58 performMicrotaskCheckpoint(); |
| 56 } | 59 } |
| 57 }, onRunAsync: (callback) => _pending.add(callback)); | 60 }, onRunAsync: (callback) => _pending.add(callback)); |
| 58 }; | 61 }; |
| 59 } | 62 } |
| 60 | |
| 61 /** | |
| 62 * This is a special kind of unit [test], that supports | |
| 63 * calling [performMicrotaskCheckpoint] during the test to pump events | |
| 64 * that original from observable objects. | |
| 65 */ | |
| 66 observeTest(name, testCase) => test(name, wrapMicrotask(testCase)); | |
| 67 | |
| 68 /** The [solo_test] version of [observeTest]. */ | |
| 69 solo_observeTest(name, testCase) => solo_test(name, wrapMicrotask(testCase)); | |
| OLD | NEW |