diff --git a/test/_specs.dart b/test/_specs.dart index 21d9dced9..e0d63cbf2 100644 --- a/test/_specs.dart +++ b/test/_specs.dart @@ -156,6 +156,7 @@ class Logger implements List { } List _asyncQueue = []; +List _asyncErrors = []; nextTurn([bool runUntilEmpty = false]) { // copy the queue as it may change. @@ -170,7 +171,15 @@ nextTurn([bool runUntilEmpty = false]) { async(Function fn) => () { - dartAsync.runZonedExperimental(fn, onRunAsync: (asyncFn) => _asyncQueue.add(asyncFn)); + _asyncErrors = []; + dartAsync.runZonedExperimental(fn, + onRunAsync: (asyncFn) => _asyncQueue.add(asyncFn), + onError: (e) => _asyncErrors.add(e)); + + _asyncErrors.forEach((e) { + throw "During runZoned: $e. Stack:\n${dartAsync.getAttachedStackTrace(e)}"; + }); + expect(_asyncQueue.isEmpty).toBe(true); }; diff --git a/test/_specs_spec.dart b/test/_specs_spec.dart index 22190e46c..252bd9f6c 100644 --- a/test/_specs_spec.dart +++ b/test/_specs_spec.dart @@ -121,5 +121,14 @@ main() { })(); }).toThrow("blah"); }); + + + it('should complain if the test throws an exception during async calls', () { + var ran = false; + expect(async(() { + new Future.value('s').then((_) { throw "blah then"; }); + nextTurn(true); + })).toThrow("blah then"); + }); }); }