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

Commit

Permalink
fix(jasmine): don't swallow exceptions in afterEach
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chirayuk committed Mar 26, 2014
1 parent a4b8c81 commit ae15983
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test/jasmine_syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ import 'package:unittest/unittest.dart' as unit;
import 'package:angular/utils.dart' as utils;

var _beforeEachFnsForCurrentTest = [];
var _afterEachFnsForCurrentTest = [];

_withSetup(fn) => () {
_beforeEachFnsForCurrentTest.sort((a, b) => Comparable.compare(b[1], a[1]));
_beforeEachFnsForCurrentTest.forEach((fn) => fn[0]());
try {
fn();
} finally {
_beforeEachFnsForCurrentTest = [];
var _aeFns = _afterEachFnsForCurrentTest;
_afterEachFnsForCurrentTest = [];
_aeFns.reversed.forEach((fn) => fn());
}
};



it(name, fn) => unit.test(name, _withSetup(fn));
iit(name, fn) => unit.solo_test(name, _withSetup(fn));
xit(name, fn) {}
Expand All @@ -35,10 +42,7 @@ class Describe {

setUp() {
_beforeEachFnsForCurrentTest.addAll(beforeEachFns);
}

tearDown() {
afterEachFns.forEach((fn) => fn());
_afterEachFnsForCurrentTest.addAll(afterEachFns);
}
}

Expand All @@ -55,7 +59,6 @@ describe(name, fn, [bool exclusive=false]) {
try {
unit.group(name, () {
unit.setUp(currentDescribe.setUp);
unit.tearDown(currentDescribe.tearDown);
fn();
});
} finally {
Expand Down Expand Up @@ -147,5 +150,4 @@ class Jasmine {

main(){
unit.setUp(currentDescribe.setUp);
unit.tearDown(currentDescribe.tearDown);
}

0 comments on commit ae15983

Please sign in to comment.