| OLD | NEW |
| (Empty) | |
| 1 library jamine; |
| 2 |
| 3 import 'package:unittest/unittest.dart' as unit; |
| 4 import 'package:angular/utils.dart' as utils; |
| 5 |
| 6 Function _wrapFn; |
| 7 |
| 8 _maybeWrapFn(fn) => () { |
| 9 if (_wrapFn != null) { |
| 10 _wrapFn(fn)(); |
| 11 } else { |
| 12 fn(); |
| 13 } |
| 14 }; |
| 15 |
| 16 it(name, fn) => unit.test(name, _maybeWrapFn(fn)); |
| 17 iit(name, fn) => unit.solo_test(name, _maybeWrapFn(fn)); |
| 18 xit(name, fn) {} |
| 19 xdescribe(name, fn) {} |
| 20 ddescribe(name, fn) => describe(name, fn, true); |
| 21 |
| 22 |
| 23 class Describe { |
| 24 Describe parent; |
| 25 String name; |
| 26 bool exclusive; |
| 27 List<Function> beforeEachFns = []; |
| 28 List<Function> afterEachFns = []; |
| 29 |
| 30 Describe(this.name, this.parent, [bool this.exclusive=false]) { |
| 31 if (parent != null && parent.exclusive) { |
| 32 exclusive = true; |
| 33 } |
| 34 } |
| 35 |
| 36 setUp() { |
| 37 beforeEachFns.forEach((fn) => fn()); |
| 38 } |
| 39 |
| 40 tearDown() { |
| 41 afterEachFns.forEach((fn) => fn()); |
| 42 } |
| 43 } |
| 44 |
| 45 Describe currentDescribe = new Describe('', null); |
| 46 bool ddescribeActive = false; |
| 47 |
| 48 describe(name, fn, [bool exclusive=false]) { |
| 49 var lastDescribe = currentDescribe; |
| 50 currentDescribe = new Describe(name, lastDescribe, exclusive); |
| 51 if (exclusive) { |
| 52 name = 'DDESCRIBE: $name'; |
| 53 ddescribeActive = true; |
| 54 } |
| 55 try { |
| 56 unit.group(name, () { |
| 57 unit.setUp(currentDescribe.setUp); |
| 58 fn(); |
| 59 unit.tearDown(currentDescribe.tearDown); |
| 60 }); |
| 61 } finally { |
| 62 currentDescribe = lastDescribe; |
| 63 } |
| 64 } |
| 65 |
| 66 beforeEach(fn) => currentDescribe.beforeEachFns.add(fn); |
| 67 afterEach(fn) => currentDescribe.afterEachFns.insert(0, fn); |
| 68 |
| 69 wrapFn(fn) => _wrapFn = fn; |
| 70 |
| 71 var jasmine = new Jasmine(); |
| 72 |
| 73 class SpyFunctionInvocationResult { |
| 74 final List args; |
| 75 SpyFunctionInvocationResult(this.args); |
| 76 } |
| 77 |
| 78 class SpyFunction { |
| 79 String name; |
| 80 List<List<dynamic>> invocations = []; |
| 81 List<List<dynamic>> invocationsWithoutTrailingNulls = []; |
| 82 var _andCallFakeFn; |
| 83 |
| 84 SpyFunction([this.name]); |
| 85 call([a0, a1, a2, a3, a4, a5]) { |
| 86 var args = []; |
| 87 args.add(a0); |
| 88 args.add(a1); |
| 89 args.add(a2); |
| 90 args.add(a3); |
| 91 args.add(a4); |
| 92 args.add(a5); |
| 93 invocations.add(args); |
| 94 |
| 95 var withoutNulls = new List.from(args); |
| 96 while (!withoutNulls.isEmpty && withoutNulls.last == null) { |
| 97 withoutNulls.removeLast(); |
| 98 } |
| 99 invocationsWithoutTrailingNulls.add(withoutNulls); |
| 100 |
| 101 if (_andCallFakeFn != null) { |
| 102 utils.relaxFnApply(_andCallFakeFn, args); |
| 103 } |
| 104 } |
| 105 |
| 106 andCallFake(fn) { |
| 107 _andCallFakeFn = fn; |
| 108 return this; |
| 109 } |
| 110 |
| 111 reset() => invocations = []; |
| 112 |
| 113 num get count => invocations.length; |
| 114 bool get called => count > 0; |
| 115 |
| 116 num get callCount => count; |
| 117 get argsForCall => invocationsWithoutTrailingNulls; |
| 118 |
| 119 firstArgsMatch(a,b,c,d,e,f) { |
| 120 var fi = invocations.first; |
| 121 assert(fi.length == 6); |
| 122 if ("${fi[0]}" != "$a") return false; |
| 123 if ("${fi[1]}" != "$b") return false; |
| 124 if ("${fi[2]}" != "$c") return false; |
| 125 if ("${fi[3]}" != "$d") return false; |
| 126 if ("${fi[4]}" != "$e") return false; |
| 127 if ("${fi[5]}" != "$f") return false; |
| 128 |
| 129 return true; |
| 130 } |
| 131 |
| 132 get mostRecentCall { |
| 133 if (invocations.isEmpty) { |
| 134 throw ["No calls"]; |
| 135 } |
| 136 return new SpyFunctionInvocationResult(invocations.last); |
| 137 } |
| 138 } |
| 139 |
| 140 class Jasmine { |
| 141 createSpy([String name]) { |
| 142 return new SpyFunction(name); |
| 143 } |
| 144 |
| 145 SpyFunction spyOn(receiver, methodName) { |
| 146 throw ["spyOn not implemented"]; |
| 147 } |
| 148 } |
| 149 |
| 150 main(){ |
| 151 unit.setUp(currentDescribe.setUp); |
| 152 unit.tearDown(currentDescribe.tearDown); |
| 153 } |
| OLD | NEW |