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

fix(async tests): Catch errors in the async calls #49

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion test/_specs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class Logger implements List {
}

List<Function> _asyncQueue = [];
List _asyncErrors = [];

nextTurn([bool runUntilEmpty = false]) {
// copy the queue as it may change.
Expand All @@ -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);
};

Expand Down
9 changes: 9 additions & 0 deletions test/_specs_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
}