@@ -220,8 +220,14 @@ class _ExpectedFunction {
220
220
/// callback when debugging. [id] should be the name of the callback, while
221
221
/// [reason] should be the reason the callback is expected to be called.
222
222
Function expectAsync (Function callback,
223
- {int count: 1 , int max: 0 , String id, String reason}) =>
224
- new _ExpectedFunction (callback, count, max, id: id, reason: reason).func;
223
+ {int count: 1 , int max: 0 , String id, String reason}) {
224
+ if (Invoker .current == null ) {
225
+ throw new StateError ("expectAsync() may only be called within a test." );
226
+ }
227
+
228
+ return new _ExpectedFunction (callback, count, max, id: id, reason: reason)
229
+ .func;
230
+ }
225
231
226
232
/// Indicate that [callback] is expected to be called until [isDone] returns
227
233
/// true.
@@ -235,5 +241,12 @@ Function expectAsync(Function callback,
235
241
/// callback when debugging. [id] should be the name of the callback, while
236
242
/// [reason] should be the reason the callback is expected to be called.
237
243
Function expectAsyncUntil (Function callback, bool isDone (),
238
- {String id, String reason}) => new _ExpectedFunction (callback, 0 , - 1 ,
239
- id: id, reason: reason, isDone: isDone).func;
244
+ {String id, String reason}) {
245
+ if (Invoker .current == null ) {
246
+ throw new StateError (
247
+ "expectAsyncUntil() may only be called within a test." );
248
+ }
249
+
250
+ return new _ExpectedFunction (callback, 0 , - 1 ,
251
+ id: id, reason: reason, isDone: isDone).func;
252
+ }
0 commit comments