| OLD | NEW |
| 1 library jasmine; | 1 library jasmine; |
| 2 | 2 |
| 3 import 'package:unittest/unittest.dart' as unit; | 3 import 'package:unittest/unittest.dart' as unit; |
| 4 import 'package:angular/utils.dart' as utils; | 4 import 'package:angular/utils.dart' as utils; |
| 5 | 5 |
| 6 Function _wrapFn; | 6 var _beforeEachFnsForCurrentTest = []; |
| 7 var _afterEachFnsForCurrentTest = []; |
| 7 | 8 |
| 8 _maybeWrapFn(fn) => () { | 9 _withSetup(fn) => () { |
| 9 if (_wrapFn != null) { | 10 _beforeEachFnsForCurrentTest.sort((a, b) => Comparable.compare(b[1], a[1])); |
| 10 _wrapFn(fn)(); | 11 _beforeEachFnsForCurrentTest.forEach((fn) => fn[0]()); |
| 11 } else { | 12 try { |
| 12 fn(); | 13 return fn(); |
| 14 } finally { |
| 15 _beforeEachFnsForCurrentTest = []; |
| 16 var _aeFns = _afterEachFnsForCurrentTest; |
| 17 _afterEachFnsForCurrentTest = []; |
| 18 _aeFns.reversed.forEach((fn) => fn()); |
| 13 } | 19 } |
| 14 }; | 20 }; |
| 15 | 21 |
| 16 it(name, fn) => unit.test(name, _maybeWrapFn(fn)); | 22 |
| 17 iit(name, fn) => unit.solo_test(name, _maybeWrapFn(fn)); | 23 |
| 24 it(name, fn) => unit.test(name, _withSetup(fn)); |
| 25 iit(name, fn) => unit.solo_test(name, _withSetup(fn)); |
| 18 xit(name, fn) {} | 26 xit(name, fn) {} |
| 19 xdescribe(name, fn) {} | 27 xdescribe(name, fn) {} |
| 20 ddescribe(name, fn) => describe(name, fn, true); | 28 ddescribe(name, fn) => describe(name, fn, true); |
| 21 | 29 |
| 22 | |
| 23 class Describe { | 30 class Describe { |
| 24 Describe parent; | 31 Describe parent; |
| 25 String name; | 32 String name; |
| 26 bool exclusive; | 33 bool exclusive; |
| 27 List<Function> beforeEachFns = []; | 34 List<List> beforeEachFns = []; |
| 28 List<Function> afterEachFns = []; | 35 List<Function> afterEachFns = []; |
| 29 | 36 |
| 30 Describe(this.name, this.parent, [bool this.exclusive=false]) { | 37 Describe(this.name, this.parent, [bool this.exclusive=false]) { |
| 31 if (parent != null && parent.exclusive) { | 38 if (parent != null && parent.exclusive) { |
| 32 exclusive = true; | 39 exclusive = true; |
| 33 } | 40 } |
| 34 } | 41 } |
| 35 | 42 |
| 36 setUp() { | 43 setUp() { |
| 37 beforeEachFns.forEach((fn) => fn()); | 44 _beforeEachFnsForCurrentTest.addAll(beforeEachFns); |
| 38 } | 45 _afterEachFnsForCurrentTest.addAll(afterEachFns); |
| 39 | |
| 40 tearDown() { | |
| 41 afterEachFns.forEach((fn) => fn()); | |
| 42 } | 46 } |
| 43 } | 47 } |
| 44 | 48 |
| 45 Describe currentDescribe = new Describe('', null); | 49 Describe currentDescribe = new Describe('', null); |
| 46 bool ddescribeActive = false; | 50 bool ddescribeActive = false; |
| 47 | 51 |
| 48 describe(name, fn, [bool exclusive=false]) { | 52 describe(name, fn, [bool exclusive=false]) { |
| 49 var lastDescribe = currentDescribe; | 53 var lastDescribe = currentDescribe; |
| 50 currentDescribe = new Describe(name, lastDescribe, exclusive); | 54 currentDescribe = new Describe(name, lastDescribe, exclusive); |
| 51 if (exclusive) { | 55 if (exclusive) { |
| 52 name = 'DDESCRIBE: $name'; | 56 name = 'DDESCRIBE: $name'; |
| 53 ddescribeActive = true; | 57 ddescribeActive = true; |
| 54 } | 58 } |
| 55 try { | 59 try { |
| 56 unit.group(name, () { | 60 unit.group(name, () { |
| 57 unit.setUp(currentDescribe.setUp); | 61 unit.setUp(currentDescribe.setUp); |
| 58 fn(); | 62 fn(); |
| 59 unit.tearDown(currentDescribe.tearDown); | |
| 60 }); | 63 }); |
| 61 } finally { | 64 } finally { |
| 62 currentDescribe = lastDescribe; | 65 currentDescribe = lastDescribe; |
| 63 } | 66 } |
| 64 } | 67 } |
| 65 | 68 |
| 66 beforeEach(fn) => currentDescribe.beforeEachFns.add(fn); | 69 beforeEach(fn, {priority: 0}) => currentDescribe.beforeEachFns.add([fn, priority
]); |
| 67 afterEach(fn) => currentDescribe.afterEachFns.insert(0, fn); | 70 afterEach(fn) => currentDescribe.afterEachFns.insert(0, fn); |
| 68 | 71 |
| 69 wrapFn(fn) => _wrapFn = fn; | |
| 70 | |
| 71 var jasmine = new Jasmine(); | 72 var jasmine = new Jasmine(); |
| 72 | 73 |
| 73 class SpyFunctionInvocationResult { | 74 class SpyFunctionInvocationResult { |
| 74 final List args; | 75 final List args; |
| 75 SpyFunctionInvocationResult(this.args); | 76 SpyFunctionInvocationResult(this.args); |
| 76 } | 77 } |
| 77 | 78 |
| 78 class SpyFunction { | 79 class SpyFunction { |
| 79 String name; | 80 String name; |
| 80 List<List<dynamic>> invocations = []; | 81 List<List<dynamic>> invocations = []; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 return new SpyFunction(name); | 143 return new SpyFunction(name); |
| 143 } | 144 } |
| 144 | 145 |
| 145 SpyFunction spyOn(receiver, methodName) { | 146 SpyFunction spyOn(receiver, methodName) { |
| 146 throw ["spyOn not implemented"]; | 147 throw ["spyOn not implemented"]; |
| 147 } | 148 } |
| 148 } | 149 } |
| 149 | 150 |
| 150 main(){ | 151 main(){ |
| 151 unit.setUp(currentDescribe.setUp); | 152 unit.setUp(currentDescribe.setUp); |
| 152 unit.tearDown(currentDescribe.tearDown); | |
| 153 } | 153 } |
| OLD | NEW |