OLD | NEW |
1 library zone_spec; | 1 library zone_spec; |
2 | 2 |
3 import '../_specs.dart'; | 3 import '../_specs.dart'; |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 main() => describe('zone', () { | 7 void main() { |
8 var zone; | 8 describe('zone', () { |
9 var exceptionHandler; | 9 var zone; |
10 beforeEach(module((Module module) { | 10 var exceptionHandler; |
11 exceptionHandler = new LoggingExceptionHandler(); | 11 beforeEachModule((Module module) { |
12 module.value(ExceptionHandler, exceptionHandler); | 12 exceptionHandler = new LoggingExceptionHandler(); |
13 })); | 13 module.value(ExceptionHandler, exceptionHandler); |
14 | 14 }); |
15 beforeEach(inject((Logger log, ExceptionHandler eh) { | 15 |
16 zone = new NgZone(); | 16 beforeEach((Logger log, ExceptionHandler eh) { |
17 zone.onTurnDone = () { | 17 zone = new VmTurnZone(); |
18 log('onTurnDone'); | 18 zone.onTurnDone = () { |
19 }; | 19 log('onTurnDone'); |
20 zone.onError = (e, s, ls) => eh(e, s); | 20 }; |
21 })); | 21 zone.onTurnStart = () { |
22 | 22 log('onTurnStart'); |
23 | 23 }; |
24 describe('exceptions', () { | 24 zone.onError = (e, s, ls) => eh(e, s); |
25 it('should rethrow exceptions from the body and call onError', () { | 25 }); |
26 var error; | 26 |
27 zone.onError = (e, s, l) => error = e; | 27 |
28 expect(() { | 28 describe('exceptions', () { |
29 zone.run(() { | 29 it('should rethrow exceptions from the body and call onError', () { |
30 throw ['hello']; | 30 var error; |
31 }); | 31 zone.onError = (e, s, l) => error = e; |
32 }).toThrow('hello'); | 32 expect(() { |
33 expect(error).toEqual(['hello']); | 33 zone.run(() { |
34 }); | 34 throw ['hello']; |
35 | 35 }); |
36 | 36 }).toThrow('hello'); |
37 it('should call onError for errors from scheduleMicrotask', async(inject(()
{ | 37 expect(error).toEqual(['hello']); |
38 zone.run(() { | 38 }); |
39 scheduleMicrotask(() { | 39 |
40 throw ["async exception"]; | 40 |
41 }); | 41 it('should call onError for errors from scheduleMicrotask', async(() { |
42 }); | |
43 | |
44 expect(exceptionHandler.errors.length).toEqual(1); | |
45 expect(exceptionHandler.errors[0].error).toEqual(["async exception"]); | |
46 }))); | |
47 | |
48 | |
49 it('should allow executing code outside the zone', inject(() { | |
50 var zone = new NgZone(); | |
51 var outerZone = Zone.current; | |
52 var ngZone; | |
53 var outsideZone; | |
54 zone.run(() { | |
55 ngZone = Zone.current; | |
56 zone.runOutsideAngular(() { | |
57 outsideZone = Zone.current; | |
58 }); | |
59 }); | |
60 | |
61 expect(outsideZone).toEqual(outerZone); | |
62 expect(ngZone.parent).toEqual((outerZone)); | |
63 })); | |
64 | |
65 | |
66 it('should rethrow exceptions from the onTurnDone and call onError when the
zone is sync', () { | |
67 zone.onTurnDone = () { | |
68 throw ["fromOnTurnDone"]; | |
69 }; | |
70 | |
71 expect(() { | |
72 zone.run(() { }); | |
73 }).toThrow('fromOnTurnDone'); | |
74 | |
75 expect(exceptionHandler.errors.length).toEqual(1); | |
76 expect(exceptionHandler.errors[0].error).toEqual(["fromOnTurnDone"]); | |
77 }); | |
78 | |
79 | |
80 it('should rethrow exceptions from the onTurnDone and call onError when the
zone is async', () { | |
81 var asyncRan = false; | |
82 | |
83 zone.onTurnDone = () { | |
84 throw ["fromOnTurnDone"]; | |
85 }; | |
86 | |
87 expect(() { | |
88 zone.run(() { | 42 zone.run(() { |
89 scheduleMicrotask(() { | 43 scheduleMicrotask(() { |
90 asyncRan = true; | 44 throw ["async exception"]; |
91 }); | 45 }); |
92 }); | 46 }); |
93 }).toThrow('fromOnTurnDone'); | 47 |
94 | 48 expect(exceptionHandler.errors.length).toEqual(1); |
95 expect(asyncRan).toBeTruthy(); | 49 expect(exceptionHandler.errors[0].error).toEqual(["async exception"]); |
96 expect(exceptionHandler.errors.length).toEqual(1); | 50 })); |
97 expect(exceptionHandler.errors[0].error).toEqual(["fromOnTurnDone"]); | 51 |
98 }); | 52 |
99 }); | 53 it('should allow executing code outside the zone', () { |
100 | 54 var zone = new VmTurnZone(); |
101 xdescribe('long stack traces', () { | 55 var outerZone = Zone.current; |
102 it('should have nice error when crossing scheduleMicrotask boundries', async
(inject(() { | 56 var ngZone; |
103 var error; | 57 var outsideZone; |
104 var stack; | 58 zone.run(() { |
105 var longStacktrace; | 59 ngZone = Zone.current; |
106 | 60 zone.runOutsideAngular(() { |
107 zone.onError = (e, s, f) { | 61 outsideZone = Zone.current; |
108 error = e; | 62 }); |
109 stack = s; | 63 }); |
110 longStacktrace = f; | 64 |
111 }; | 65 expect(outsideZone).toEqual(outerZone); |
112 var FRAME = new RegExp(r'.*\(.*\:(\d+):\d+\)'); | 66 expect(ngZone.parent).toEqual((outerZone)); |
113 | 67 }); |
114 var line = ((){ try {throw [];} catch(e, s) { return int.parse(FRAME.first
Match('$s')[1]);}})(); | 68 |
115 var throwFn = () { throw ['double zonned']; }; | 69 |
116 var inner = () => zone.run(throwFn); | 70 it('should rethrow exceptions from the onTurnDone and call onError when th
e zone is sync', () { |
117 var middle = () => scheduleMicrotask(inner); | 71 zone.onTurnDone = () { |
118 var outer = () => scheduleMicrotask(middle); | 72 throw ["fromOnTurnDone"]; |
119 zone.run(outer); | 73 }; |
120 | 74 |
121 microLeap(); | 75 expect(() { |
122 expect(error).toEqual(['double zonned']); | 76 zone.run(() { }); |
123 | 77 }).toThrow('fromOnTurnDone'); |
124 // Not in dart2js.. | 78 |
125 if ('$stack'.contains('.dart.js')) { | 79 expect(exceptionHandler.errors.length).toEqual(1); |
126 return; | 80 expect(exceptionHandler.errors[0].error).toEqual(["fromOnTurnDone"]); |
127 } | 81 }); |
128 | 82 |
129 expect('$stack').toContain('zone_spec.dart:${line+1}'); | 83 |
130 expect('$stack').toContain('zone_spec.dart:${line+2}'); | 84 it('should rethrow exceptions from the onTurnDone and call onError when th
e zone is async', () { |
131 expect('$longStacktrace').toContain('zone_spec.dart:${line+3}'); | 85 var asyncRan = false; |
132 expect('$longStacktrace').toContain('zone_spec.dart:${line+4}'); | 86 |
133 expect('$longStacktrace').toContain('zone_spec.dart:${line+5}'); | 87 zone.onTurnDone = () { |
134 }))); | 88 throw ["fromOnTurnDone"]; |
135 }); | 89 }; |
136 | 90 |
137 it('should call onTurnDone after a synchronous block', inject((Logger log) { | 91 expect(() { |
138 zone.run(() { | 92 zone.run(() { |
139 log('run'); | 93 scheduleMicrotask(() { |
140 }); | 94 asyncRan = true; |
141 expect(log.result()).toEqual('run; onTurnDone'); | 95 }); |
142 })); | 96 }); |
143 | 97 }).toThrow('fromOnTurnDone'); |
144 | 98 |
145 it('should return the body return value from run', () { | 99 expect(asyncRan).toBeTruthy(); |
146 expect(zone.run(() { return 6; })).toEqual(6); | 100 expect(exceptionHandler.errors.length).toEqual(1); |
147 }); | 101 expect(exceptionHandler.errors[0].error).toEqual(["fromOnTurnDone"]); |
148 | 102 }); |
149 | 103 }); |
150 it('should call onTurnDone for a scheduleMicrotask in onTurnDone', async(injec
t((Logger log) { | 104 |
151 var ran = false; | 105 xdescribe('long stack traces', () { |
152 zone.onTurnDone = () { | 106 it('should have nice error when crossing scheduleMicrotask boundries', asy
nc(() { |
153 if (!ran) { | 107 var error; |
154 scheduleMicrotask(() { ran = true; log('onTurnAsync'); }); | 108 var stack; |
155 } | 109 var longStacktrace; |
156 log('onTurnDone'); | 110 |
157 }; | 111 zone.onError = (e, s, f) { |
158 zone.run(() { | 112 error = e; |
159 log('run'); | 113 stack = s; |
160 }); | 114 longStacktrace = f; |
161 microLeap(); | 115 }; |
162 | 116 var FRAME = new RegExp(r'.*\(.*\:(\d+):\d+\)'); |
163 expect(log.result()).toEqual('run; onTurnDone; onTurnAsync; onTurnDone'); | 117 |
164 }))); | 118 var line = ((){ try {throw [];} catch(e, s) { return int.parse(FRAME.fir
stMatch('$s')[1]);}})(); |
165 | 119 var throwFn = () { throw ['double zonned']; }; |
166 | 120 var inner = () => zone.run(throwFn); |
167 it('should call onTurnDone for a scheduleMicrotask in onTurnDone triggered by
a scheduleMicrotask in run', async(inject((Logger log) { | 121 var middle = () => scheduleMicrotask(inner); |
168 var ran = false; | 122 var outer = () => scheduleMicrotask(middle); |
169 zone.onTurnDone = () { | 123 zone.run(outer); |
170 if (!ran) { | 124 |
171 scheduleMicrotask(() { ran = true; log('onTurnAsync'); }); | 125 microLeap(); |
172 } | 126 expect(error).toEqual(['double zonned']); |
173 log('onTurnDone'); | 127 |
174 }; | 128 // Not in dart2js.. |
175 zone.run(() { | 129 if ('$stack'.contains('.dart.js')) { |
176 scheduleMicrotask(() { log('scheduleMicrotask'); }); | 130 return; |
177 log('run'); | 131 } |
178 }); | 132 |
179 microLeap(); | 133 expect('$stack').toContain('zone_spec.dart:${line+1}'); |
180 | 134 expect('$stack').toContain('zone_spec.dart:${line+2}'); |
181 expect(log.result()).toEqual('run; scheduleMicrotask; onTurnDone; onTurnAsyn
c; onTurnDone'); | 135 expect('$longStacktrace').toContain('zone_spec.dart:${line+3}'); |
182 }))); | 136 expect('$longStacktrace').toContain('zone_spec.dart:${line+4}'); |
183 | 137 expect('$longStacktrace').toContain('zone_spec.dart:${line+5}'); |
184 | 138 })); |
185 | 139 }); |
186 it('should call onTurnDone once after a turn', async(inject((Logger log) { | 140 |
187 zone.run(() { | 141 it('should call onTurnDone after a synchronous view', (Logger log) { |
188 log('run start'); | 142 zone.run(() { |
189 scheduleMicrotask(() { | 143 log('run'); |
190 log('async'); | 144 }); |
191 }); | 145 expect(log.result()).toEqual('onTurnStart; run; onTurnDone'); |
192 log('run end'); | 146 }); |
193 }); | 147 |
194 microLeap(); | 148 |
195 | 149 it('should return the body return value from run', () { |
196 expect(log.result()).toEqual('run start; run end; async; onTurnDone'); | 150 expect(zone.run(() { return 6; })).toEqual(6); |
197 }))); | 151 }); |
198 | 152 |
199 | 153 |
200 it('should work for Future.value as well', async(inject((Logger log) { | 154 it('should call onTurnStart before executing a microtask scheduled in onTurn
Done as well as ' |
201 var futureRan = false; | 155 'onTurnDone after executing the task', async((Logger log) { |
202 zone.onTurnDone = () { | 156 var ran = false; |
203 if (!futureRan) { | 157 zone.onTurnDone = () { |
204 new Future.value(null).then((_) { log('onTurn future'); }); | 158 log('onTurnDone(begin)'); |
205 futureRan = true; | 159 if (!ran) { |
206 } | 160 scheduleMicrotask(() { ran = true; log('executedMicrotask'); }); |
207 log('onTurnDone'); | 161 } |
208 }; | 162 log('onTurnDone(end)'); |
209 | 163 }; |
210 zone.run(() { | 164 zone.run(() { |
211 log('run start'); | 165 log('run'); |
212 new Future.value(null) | 166 }); |
| 167 microLeap(); |
| 168 |
| 169 expect(log.result()).toEqual('onTurnStart; run; onTurnDone(begin); onTurnD
one(end); onTurnStart; executedMicrotask; onTurnDone(begin); onTurnDone(end)'); |
| 170 })); |
| 171 |
| 172 |
| 173 it('should call onTurnStart and onTurnDone for a scheduleMicrotask in onTurn
Done triggered by a scheduleMicrotask in run', async((Logger log) { |
| 174 var ran = false; |
| 175 zone.onTurnDone = () { |
| 176 log('onTurnDone(begin)'); |
| 177 if (!ran) { |
| 178 log('onTurnDone(scheduleMicrotask)'); |
| 179 scheduleMicrotask(() { |
| 180 ran = true; |
| 181 log('onTurnDone(executeMicrotask)'); |
| 182 }); |
| 183 } |
| 184 log('onTurnDone(end)'); |
| 185 }; |
| 186 zone.run(() { |
| 187 log('scheduleMicrotask'); |
| 188 scheduleMicrotask(() { |
| 189 log('run(executeMicrotask)'); |
| 190 }); |
| 191 }); |
| 192 microLeap(); |
| 193 |
| 194 expect(log.result()).toEqual('onTurnStart; scheduleMicrotask; run(executeM
icrotask); onTurnDone(begin); onTurnDone(scheduleMicrotask); onTurnDone(end); on
TurnStart; onTurnDone(executeMicrotask); onTurnDone(begin); onTurnDone(end)'); |
| 195 })); |
| 196 |
| 197 |
| 198 |
| 199 it('should call onTurnStart once before a turn and onTurnDone once after the
turn', async((Logger log) { |
| 200 zone.run(() { |
| 201 log('run start'); |
| 202 scheduleMicrotask(() { |
| 203 log('async'); |
| 204 }); |
| 205 log('run end'); |
| 206 }); |
| 207 microLeap(); |
| 208 |
| 209 expect(log.result()).toEqual('onTurnStart; run start; run end; async; onTu
rnDone'); |
| 210 })); |
| 211 |
| 212 |
| 213 it('should work for Future.value as well', async((Logger log) { |
| 214 var futureRan = false; |
| 215 zone.onTurnDone = () { |
| 216 log('onTurnDone(begin)'); |
| 217 if (!futureRan) { |
| 218 log('onTurnDone(scheduleFuture)'); |
| 219 new Future.value(null).then((_) { log('onTurnDone(executeFuture)'); })
; |
| 220 futureRan = true; |
| 221 } |
| 222 log('onTurnDone(end)'); |
| 223 }; |
| 224 |
| 225 zone.run(() { |
| 226 log('run start'); |
| 227 new Future.value(null) |
213 .then((_) { | 228 .then((_) { |
214 log('future then'); | 229 log('future then'); |
215 new Future.value(null) | 230 new Future.value(null) |
216 .then((_) { log('future ?'); }); | 231 .then((_) { log('future foo'); }); |
217 return new Future.value(null); | 232 return new Future.value(null); |
218 }) | 233 }) |
219 .then((_) { | 234 .then((_) { |
220 log('future ?'); | 235 log('future bar'); |
221 }); | 236 }); |
222 log('run end'); | 237 log('run end'); |
223 }); | 238 }); |
224 microLeap(); | 239 microLeap(); |
225 | 240 |
226 expect(log.result()).toEqual('run start; run end; future then; future ?; fut
ure ?; onTurnDone; onTurn future; onTurnDone'); | 241 expect(log.result()).toEqual('onTurnStart; run start; run end; future then
; future foo; future bar; onTurnDone(begin); onTurnDone(scheduleFuture); onTurnD
one(end); onTurnStart; onTurnDone(executeFuture); onTurnDone(begin); onTurnDone(
end)'); |
227 }))); | 242 })); |
228 | 243 |
229 | 244 it('should execute futures scheduled in onTurnStart before Futures scheduled
in run', async((Logger log) { |
230 it('should call onTurnDone after each turn', async(inject((Logger log) { | 245 var doneFutureRan = false; |
231 Completer a, b; | 246 var startFutureRan = false; |
232 zone.run(() { | 247 zone.onTurnStart = () { |
233 a = new Completer(); | 248 log('onTurnStart(begin)'); |
234 b = new Completer(); | 249 if (!startFutureRan) { |
235 a.future.then((_) => log('a then')); | 250 log('onTurnStart(scheduleFuture)'); |
236 b.future.then((_) => log('b then')); | 251 new Future.value(null).then((_) { log('onTurnStart(executeFuture)'); }
); |
237 log('run start'); | 252 startFutureRan = true; |
238 }); | 253 } |
239 microLeap(); | 254 log('onTurnStart(end)'); |
240 zone.run(() { | 255 }; |
241 a.complete(null); | 256 zone.onTurnDone = () { |
242 }); | 257 log('onTurnDone(begin)'); |
243 microLeap(); | 258 if (!doneFutureRan) { |
244 zone.run(() { | 259 log('onTurnDone(scheduleFuture)'); |
245 b.complete(null); | 260 new Future.value(null).then((_) { log('onTurnDone(executeFuture)'); })
; |
246 }); | 261 doneFutureRan = true; |
247 microLeap(); | 262 } |
248 | 263 log('onTurnDone(end)'); |
249 expect(log.result()).toEqual('run start; onTurnDone; a then; onTurnDone; b t
hen; onTurnDone'); | 264 }; |
250 }))); | 265 |
251 | 266 zone.run(() { |
252 | 267 log('run start'); |
253 it('should call onTurnDone after each turn in a chain', async(inject((Logger l
og) { | 268 new Future.value(null) |
254 zone.run(() { | 269 .then((_) { |
255 log('run start'); | 270 log('future then'); |
256 scheduleMicrotask(() { | 271 new Future.value(null) |
257 log('async1'); | 272 .then((_) { log('future foo'); }); |
258 scheduleMicrotask(() { | 273 return new Future.value(null); |
259 log('async2'); | 274 }) |
260 }); | 275 .then((_) { |
261 }); | 276 log('future bar'); |
262 log('run end'); | 277 }); |
263 }); | 278 log('run end'); |
264 microLeap(); | 279 }); |
265 | 280 microLeap(); |
266 expect(log.result()).toEqual('run start; run end; async1; async2; onTurnDone
'); | 281 |
267 }))); | 282 expect(log.result()).toEqual('onTurnStart(begin); onTurnStart(scheduleFutu
re); onTurnStart(end); run start; run end; onTurnStart(executeFuture); future th
en; future foo; future bar; onTurnDone(begin); onTurnDone(scheduleFuture); onTur
nDone(end); onTurnStart(begin); onTurnStart(end); onTurnDone(executeFuture); onT
urnDone(begin); onTurnDone(end)'); |
268 | 283 })); |
269 it('should call onTurnDone for futures created outside of run body', async(inj
ect((Logger log) { | 284 |
270 var future = new Future.value(4).then((x) => new Future.value(x)); | 285 |
271 zone.run(() { | 286 it('should call onTurnStart and onTurnDone before and after each turn, resp
ectively', async((Logger log) { |
272 future.then((_) => log('future then')); | 287 Completer a, b; |
273 log('zone run'); | 288 zone.run(() { |
274 }); | 289 a = new Completer(); |
275 microLeap(); | 290 b = new Completer(); |
276 | 291 a.future.then((_) => log('a then')); |
277 expect(log.result()).toEqual('zone run; onTurnDone; future then; onTurnDone'
); | 292 b.future.then((_) => log('b then')); |
278 }))); | 293 log('run start'); |
279 | 294 }); |
280 | 295 microLeap(); |
281 it('should call onTurnDone even if there was an exception in body', async(inje
ct((Logger log) { | 296 zone.run(() { |
282 zone.onError = (e, s, l) => log('onError'); | 297 a.complete(null); |
283 expect(() => zone.run(() { | 298 }); |
284 log('zone run'); | 299 microLeap(); |
285 throw 'zoneError'; | 300 zone.run(() { |
286 })).toThrow('zoneError'); | 301 b.complete(null); |
287 expect(() => zone.assertInTurn()).toThrow(); | 302 }); |
288 expect(log.result()).toEqual('zone run; onError; onTurnDone'); | 303 microLeap(); |
289 }))); | 304 |
290 | 305 expect(log.result()).toEqual('onTurnStart; run start; onTurnDone; onTurnSt
art; a then; onTurnDone; onTurnStart; b then; onTurnDone'); |
291 | 306 })); |
292 it('should call onTurnDone even if there was an exception in scheduleMicrotask
', async(inject((Logger log) { | 307 |
293 zone.onError = (e, s, l) => log('onError'); | 308 |
294 zone.run(() { | 309 it('should call onTurnStart and onTurnDone before and after (respectively) a
ll turns in a chain', async((Logger log) { |
295 log('zone run'); | 310 zone.run(() { |
296 scheduleMicrotask(() { | 311 log('run start'); |
297 log('scheduleMicrotask'); | 312 scheduleMicrotask(() { |
298 throw new Error(); | 313 log('async1'); |
299 }); | 314 scheduleMicrotask(() { |
300 }); | 315 log('async2'); |
301 | 316 }); |
302 microLeap(); | 317 }); |
303 | 318 log('run end'); |
304 expect(() => zone.assertInTurn()).toThrow(); | 319 }); |
305 expect(log.result()).toEqual('zone run; scheduleMicrotask; onError; onTurnDo
ne'); | 320 microLeap(); |
306 }))); | 321 |
307 | 322 expect(log.result()).toEqual('onTurnStart; run start; run end; async1; asy
nc2; onTurnDone'); |
308 it('should support assertInZone', async(() { | 323 })); |
309 var calls = ''; | 324 |
310 zone.onTurnDone = () { | 325 it('should call onTurnStart and onTurnDone for futures created outside of ru
n body', async((Logger log) { |
311 zone.assertInZone(); | 326 var future = new Future.value(4).then((x) => new Future.value(x)); |
312 calls += 'done;'; | 327 zone.run(() { |
313 }; | 328 future.then((_) => log('future then')); |
314 zone.run(() { | 329 log('zone run'); |
315 zone.assertInZone(); | 330 }); |
316 calls += 'sync;'; | 331 microLeap(); |
317 scheduleMicrotask(() { | 332 |
| 333 expect(log.result()).toEqual('onTurnStart; zone run; onTurnDone; onTurnSta
rt; future then; onTurnDone'); |
| 334 })); |
| 335 |
| 336 |
| 337 it('should call onTurnDone even if there was an exception in body', async((L
ogger log) { |
| 338 zone.onError = (e, s, l) => log('onError'); |
| 339 expect(() => zone.run(() { |
| 340 log('zone run'); |
| 341 throw 'zoneError'; |
| 342 })).toThrow('zoneError'); |
| 343 expect(() => zone.assertInTurn()).toThrow(); |
| 344 expect(log.result()).toEqual('onTurnStart; zone run; onError; onTurnDone')
; |
| 345 })); |
| 346 |
| 347 it('should call onTurnDone even if there was an exception in onTurnStart', a
sync((Logger log) { |
| 348 zone.onError = (e, s, l) => log('onError'); |
| 349 zone.onTurnStart = (){ |
| 350 log('onTurnStart'); |
| 351 throw 'zoneError'; |
| 352 }; |
| 353 expect(() => zone.run(() { |
| 354 log('zone run'); |
| 355 })).toThrow('zoneError'); |
| 356 expect(() => zone.assertInTurn()).toThrow(); |
| 357 expect(log.result()).toEqual('onTurnStart; onError; onTurnDone'); |
| 358 })); |
| 359 |
| 360 |
| 361 it('should call onTurnDone even if there was an exception in scheduleMicrota
sk', async((Logger log) { |
| 362 zone.onError = (e, s, l) => log('onError'); |
| 363 zone.run(() { |
| 364 log('zone run'); |
| 365 scheduleMicrotask(() { |
| 366 log('scheduleMicrotask'); |
| 367 throw new Error(); |
| 368 }); |
| 369 }); |
| 370 |
| 371 microLeap(); |
| 372 |
| 373 expect(() => zone.assertInTurn()).toThrow(); |
| 374 expect(log.result()).toEqual('onTurnStart; zone run; scheduleMicrotask; on
Error; onTurnDone'); |
| 375 })); |
| 376 |
| 377 it('should support assertInZone', async(() { |
| 378 var calls = ''; |
| 379 zone.onTurnStart = () { |
318 zone.assertInZone(); | 380 zone.assertInZone(); |
319 calls += 'async;'; | 381 calls += 'start;'; |
320 }); | 382 }; |
321 }); | 383 zone.onTurnDone = () { |
322 | 384 zone.assertInZone(); |
323 microLeap(); | 385 calls += 'done;'; |
324 expect(calls).toEqual('sync;async;done;'); | 386 }; |
325 })); | 387 zone.run(() { |
326 | 388 zone.assertInZone(); |
327 it('should throw outside of the zone', () { | 389 calls += 'sync;'; |
328 expect(async(() { | 390 scheduleMicrotask(() { |
329 zone.assertInZone(); | 391 zone.assertInZone(); |
330 microLeap(); | 392 calls += 'async;'; |
331 })).toThrow(); | 393 }); |
| 394 }); |
| 395 |
| 396 microLeap(); |
| 397 expect(calls).toEqual('start;sync;async;done;'); |
| 398 })); |
| 399 |
| 400 it('should throw outside of the zone', () { |
| 401 expect(async(() { |
| 402 zone.assertInZone(); |
| 403 microLeap(); |
| 404 })).toThrow(); |
| 405 }); |
| 406 |
| 407 |
| 408 it('should support assertInTurn', async(() { |
| 409 var calls = ''; |
| 410 zone.onTurnStart = () { |
| 411 zone.assertInTurn(); |
| 412 calls += 'start;'; |
| 413 }; |
| 414 zone.onTurnDone = () { |
| 415 calls += 'done;'; |
| 416 zone.assertInTurn(); |
| 417 }; |
| 418 zone.run(() { |
| 419 calls += 'sync;'; |
| 420 zone.assertInTurn(); |
| 421 scheduleMicrotask(() { |
| 422 calls += 'async;'; |
| 423 zone.assertInTurn(); |
| 424 }); |
| 425 }); |
| 426 |
| 427 microLeap(); |
| 428 expect(calls).toEqual('start;sync;async;done;'); |
| 429 })); |
| 430 |
| 431 |
| 432 it('should assertInTurn outside of the zone', () { |
| 433 expect(async(() { |
| 434 zone.assertInTurn(); |
| 435 microLeap(); |
| 436 })).toThrow('ssertion'); // Support both dart2js and the VM with half a w
ord. |
| 437 }); |
332 }); | 438 }); |
333 | 439 } |
334 | |
335 it('should support assertInTurn', async(() { | |
336 var calls = ''; | |
337 zone.onTurnDone = () { | |
338 calls += 'done;'; | |
339 zone.assertInTurn(); | |
340 }; | |
341 zone.run(() { | |
342 calls += 'sync;'; | |
343 zone.assertInTurn(); | |
344 scheduleMicrotask(() { | |
345 calls += 'async;'; | |
346 zone.assertInTurn(); | |
347 }); | |
348 }); | |
349 | |
350 microLeap(); | |
351 expect(calls).toEqual('sync;async;done;'); | |
352 })); | |
353 | |
354 | |
355 it('should assertInTurn outside of the zone', () { | |
356 expect(async(() { | |
357 zone.assertInTurn(); | |
358 microLeap(); | |
359 })).toThrow('ssertion'); // Support both dart2js and the VM with half a wor
d. | |
360 }); | |
361 }); | |
OLD | NEW |