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

Commit ae15983

Browse files
committed
fix(jasmine): don't swallow exceptions in afterEach
It turns out that `tearDown()` in `unittest/unittest.dart` swallows exceptions (at least in the current version.)  This means that exceptions thrown in our `afterEach` functions are silently swallowed and cause our tests to pass incorrectly.  As an example, the 24 tests that were updated in commit d663667 should have been failing with the exception `Unflushed requests: 1` but did not.  This change makes it so that these exceptions do show up.
1 parent a4b8c81 commit ae15983

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

test/jasmine_syntax.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ import 'package:unittest/unittest.dart' as unit;
44
import 'package:angular/utils.dart' as utils;
55

66
var _beforeEachFnsForCurrentTest = [];
7+
var _afterEachFnsForCurrentTest = [];
8+
79
_withSetup(fn) => () {
810
_beforeEachFnsForCurrentTest.sort((a, b) => Comparable.compare(b[1], a[1]));
911
_beforeEachFnsForCurrentTest.forEach((fn) => fn[0]());
1012
try {
1113
fn();
1214
} finally {
1315
_beforeEachFnsForCurrentTest = [];
16+
var _aeFns = _afterEachFnsForCurrentTest;
17+
_afterEachFnsForCurrentTest = [];
18+
_aeFns.reversed.forEach((fn) => fn());
1419
}
1520
};
1621

22+
23+
1724
it(name, fn) => unit.test(name, _withSetup(fn));
1825
iit(name, fn) => unit.solo_test(name, _withSetup(fn));
1926
xit(name, fn) {}
@@ -35,10 +42,7 @@ class Describe {
3542

3643
setUp() {
3744
_beforeEachFnsForCurrentTest.addAll(beforeEachFns);
38-
}
39-
40-
tearDown() {
41-
afterEachFns.forEach((fn) => fn());
45+
_afterEachFnsForCurrentTest.addAll(afterEachFns);
4246
}
4347
}
4448

@@ -55,7 +59,6 @@ describe(name, fn, [bool exclusive=false]) {
5559
try {
5660
unit.group(name, () {
5761
unit.setUp(currentDescribe.setUp);
58-
unit.tearDown(currentDescribe.tearDown);
5962
fn();
6063
});
6164
} finally {
@@ -147,5 +150,4 @@ class Jasmine {
147150

148151
main(){
149152
unit.setUp(currentDescribe.setUp);
150-
unit.tearDown(currentDescribe.tearDown);
151153
}

0 commit comments

Comments
 (0)