Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 17be163

Browse files
committed
fix(async tests): Catch errors in the async calls
1 parent 6be5b80 commit 17be163

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

test/_specs.dart

+10-1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class Logger implements List {
156156
}
157157

158158
List<Function> _asyncQueue = [];
159+
List _asyncErrors = [];
159160

160161
nextTurn([bool runUntilEmpty = false]) {
161162
// copy the queue as it may change.
@@ -170,7 +171,15 @@ nextTurn([bool runUntilEmpty = false]) {
170171

171172
async(Function fn) =>
172173
() {
173-
dartAsync.runZonedExperimental(fn, onRunAsync: (asyncFn) => _asyncQueue.add(asyncFn));
174+
_asyncErrors = [];
175+
dartAsync.runZonedExperimental(fn,
176+
onRunAsync: (asyncFn) => _asyncQueue.add(asyncFn),
177+
onError: (e) => _asyncErrors.add(e));
178+
179+
_asyncErrors.forEach((e) {
180+
throw "During runZoned: $e. Stack:\n${dartAsync.getAttachedStackTrace(e)}";
181+
});
182+
174183
expect(_asyncQueue.isEmpty).toBe(true);
175184
};
176185

test/_specs_spec.dart

+9
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,14 @@ main() {
121121
})();
122122
}).toThrow("blah");
123123
});
124+
125+
126+
it('should complain if the test throws an exception during async calls', () {
127+
var ran = false;
128+
expect(async(() {
129+
new Future.value('s').then((_) { throw "blah then"; });
130+
nextTurn(true);
131+
})).toThrow("blah then");
132+
});
124133
});
125134
}

0 commit comments

Comments
 (0)