OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import 'dart:async'; | |
6 | |
7 import 'package:async/async.dart'; | |
8 import 'package:fake_async/fake_async.dart'; | |
9 import 'package:test/test.dart'; | |
10 | |
11 main() { | |
12 test("runs the callback once the duration has elapsed", () { | |
13 new FakeAsync().run((async) { | |
14 var fired = false; | |
15 var timer = new ResetTimer(new Duration(seconds: 5), () => fired = true); | |
Lasse Reichstein Nielsen
2015/10/27 09:45:14
Use braces, not =>, for functions where the return
nweiz
2015/10/27 21:08:12
Done.
| |
16 | |
17 async.elapse(new Duration(seconds: 4)); | |
18 expect(fired, isFalse); | |
19 | |
20 async.elapse(new Duration(seconds: 1)); | |
21 expect(fired, isTrue); | |
22 }); | |
23 }); | |
24 | |
25 test("doesn't run the callback if the timer is canceled", () { | |
26 new FakeAsync().run((async) { | |
27 var fired = false; | |
28 var timer = new ResetTimer(new Duration(seconds: 5), () => fired = true); | |
29 | |
30 async.elapse(new Duration(seconds: 4)); | |
31 expect(fired, isFalse); | |
32 timer.cancel(); | |
33 | |
34 async.elapse(new Duration(seconds: 4)); | |
Lasse Reichstein Nielsen
2015/10/27 09:45:14
Interesting - this looks like it's synchronous, so
nweiz
2015/10/27 21:08:12
I believe it just creates an entire simulated even
| |
35 expect(fired, isFalse); | |
36 }); | |
37 }); | |
38 | |
39 test("resets the duration if the timer is reset before it fires", () { | |
40 new FakeAsync().run((async) { | |
41 var fired = false; | |
42 var timer = new ResetTimer(new Duration(seconds: 5), () => fired = true); | |
43 | |
44 async.elapse(new Duration(seconds: 4)); | |
45 expect(fired, isFalse); | |
46 timer.reset(); | |
47 | |
48 async.elapse(new Duration(seconds: 4)); | |
49 expect(fired, isFalse); | |
50 | |
51 async.elapse(new Duration(seconds: 1)); | |
52 expect(fired, isTrue); | |
53 }); | |
54 }); | |
55 | |
56 test("re-runs the callback if the timer is reset after firing", () { | |
57 new FakeAsync().run((async) { | |
58 var fired = 0; | |
59 var timer = new ResetTimer(new Duration(seconds: 5), () => fired++); | |
60 | |
61 async.elapse(new Duration(seconds: 5)); | |
62 expect(fired, equals(1)); | |
63 timer.reset(); | |
64 | |
65 async.elapse(new Duration(seconds: 5)); | |
66 expect(fired, equals(2)); | |
67 timer.reset(); | |
68 | |
69 async.elapse(new Duration(seconds: 5)); | |
70 expect(fired, equals(3)); | |
71 }); | |
72 }); | |
73 | |
74 test("runs the callback if the timer is reset after being canceled", () { | |
75 new FakeAsync().run((async) { | |
76 var fired = false; | |
77 var timer = new ResetTimer(new Duration(seconds: 5), () => fired = true); | |
78 | |
79 async.elapse(new Duration(seconds: 4)); | |
80 expect(fired, isFalse); | |
81 timer.cancel(); | |
82 | |
83 async.elapse(new Duration(seconds: 4)); | |
84 expect(fired, isFalse); | |
85 timer.reset(); | |
86 | |
87 async.elapse(new Duration(seconds: 5)); | |
88 expect(fired, isTrue); | |
89 }); | |
90 }); | |
Lasse Reichstein Nielsen
2015/10/27 09:45:14
Check that the timer is not periodic: Wait at leas
nweiz
2015/10/27 21:08:12
Done.
| |
91 } | |
OLD | NEW |