Index: test/backend/declarer_test.dart |
diff --git a/test/backend/declarer_test.dart b/test/backend/declarer_test.dart |
index 91a806ece5e958edb9627754c6d02da981825ad0..22537c2b0c85b88a34f33fa86639e1ee08d019c4 100644 |
--- a/test/backend/declarer_test.dart |
+++ b/test/backend/declarer_test.dart |
@@ -5,10 +5,13 @@ |
import 'dart:async'; |
import 'package:test/src/backend/declarer.dart'; |
+import 'package:test/src/backend/invoker.dart'; |
import 'package:test/src/backend/suite.dart'; |
import 'package:test/src/frontend/timeout.dart'; |
import 'package:test/test.dart'; |
+import '../utils.dart'; |
+ |
Declarer _declarer; |
Suite _suite; |
@@ -102,6 +105,20 @@ void main() { |
expect(tearDownRun, isTrue); |
}); |
+ test("is run after an asynchronous failure", () async { |
+ var tearDownRun; |
+ _declarer.setUp(() => tearDownRun = false); |
+ _declarer.tearDown(() => tearDownRun = true); |
+ |
+ _declarer.test("description 1", expectAsync(() { |
Bob Nystrom
2015/09/24 16:05:02
Can you just make this function async and use a re
nweiz
2015/09/24 19:56:20
Done.
|
+ Invoker.current.addOutstandingCallback(); |
+ new Future(() => throw new TestFailure("oh no")); |
+ }, max: 1)); |
+ |
+ await _runTest(0, shouldFail: true); |
+ expect(tearDownRun, isTrue); |
+ }); |
+ |
test("can return a Future", () async { |
var tearDownRun = false; |
_declarer.tearDown(() { |
@@ -116,6 +133,41 @@ void main() { |
expect(tearDownRun, isTrue); |
}); |
+ test("isn't run until there are no outstanding callbacks", () async { |
+ var outstandingCallbackRemoved = false; |
+ var outstandingCallbackRemovedBeforeTeardown = false; |
+ _declarer.tearDown(() { |
+ outstandingCallbackRemovedBeforeTeardown = outstandingCallbackRemoved; |
+ }); |
+ |
+ _declarer.test("description", () { |
+ Invoker.current.addOutstandingCallback(); |
+ pumpEventQueue().then((_) { |
+ outstandingCallbackRemoved = true; |
+ Invoker.current.removeOutstandingCallback(); |
+ }); |
+ }); |
+ |
+ await _runTest(0); |
+ expect(outstandingCallbackRemovedBeforeTeardown, isTrue); |
+ }); |
+ |
+ test("doesn't complete until there are no outstanding callbacks", () async { |
+ var outstandingCallbackRemoved = false; |
+ _declarer.tearDown(() { |
+ Invoker.current.addOutstandingCallback(); |
+ pumpEventQueue().then((_) { |
+ outstandingCallbackRemoved = true; |
+ Invoker.current.removeOutstandingCallback(); |
+ }); |
+ }); |
+ |
+ _declarer.test("description", () {}); |
+ |
+ await _runTest(0); |
+ expect(outstandingCallbackRemoved, isTrue); |
+ }); |
+ |
test("can't be called multiple times", () { |
_declarer.tearDown(() {}); |
expect(() => _declarer.tearDown(() {}), throwsStateError); |
@@ -351,9 +403,13 @@ void main() { |
/// |
/// This automatically sets up an `onError` listener to ensure that the test |
/// doesn't throw any invisible exceptions. |
-Future _runTest(int index) { |
+Future _runTest(int index, {bool shouldFail: false}) { |
var liveTest = _declarer.tests[index].load(_suite); |
- liveTest.onError.listen(expectAsync((_) {}, |
- count: 0, reason: "No errors expected for test #$index.")); |
+ |
+ liveTest.onError.listen(shouldFail |
+ ? expectAsync((_) {}) |
+ : expectAsync((_) {}, |
+ count: 0, reason: "No errors expected for test #$index.")); |
+ |
return liveTest.run(); |
} |