This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree 2 files changed +31
-3
lines changed
2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change 51
51
}
52
52
53
53
tick ( millis : number = 0 ) : void {
54
- this . _currentTime += millis ;
55
- while ( this . _schedulerQueue . length > 0 ) {
54
+ let finalTime = this . _currentTime + millis ;
55
+ while ( this . _schedulerQueue . length > 0 ) {
56
56
let current = this . _schedulerQueue [ 0 ] ;
57
- if ( this . _currentTime < current . endTime ) {
57
+ if ( finalTime < current . endTime ) {
58
58
// Done processing the queue since it's sorted by endTime.
59
59
break ;
60
60
} else {
61
61
// Time to run scheduled function. Remove it from the head of queue.
62
62
let current = this . _schedulerQueue . shift ( ) ;
63
+ this . _currentTime = current . endTime ;
63
64
let retval = current . func . apply ( global , current . args ) ;
64
65
if ( ! retval ) {
65
66
// Uncaught exception in the current scheduled function. Stop processing the queue.
66
67
break ;
67
68
}
68
69
}
69
70
}
71
+ this . _currentTime = finalTime ;
70
72
}
71
73
}
72
74
Original file line number Diff line number Diff line change @@ -119,6 +119,29 @@ describe('FakeAsyncTestZoneSpec', () => {
119
119
} ) ;
120
120
} ) ;
121
121
122
+ it ( 'should run queued timer created by timer callback' , ( ) => {
123
+ fakeAsyncTestZone . run ( ( ) => {
124
+ let counter = 0 ;
125
+ const startCounterLoop = ( ) => {
126
+ counter ++ ;
127
+ setTimeout ( startCounterLoop , 10 ) ;
128
+ }
129
+
130
+ startCounterLoop ( ) ;
131
+
132
+ expect ( counter ) . toEqual ( 1 ) ;
133
+
134
+ testZoneSpec . tick ( 10 ) ;
135
+ expect ( counter ) . toEqual ( 2 ) ;
136
+
137
+ testZoneSpec . tick ( 10 ) ;
138
+ expect ( counter ) . toEqual ( 3 ) ;
139
+
140
+ testZoneSpec . tick ( 30 ) ;
141
+ expect ( counter ) . toEqual ( 6 ) ;
142
+ } ) ;
143
+ } ) ;
144
+
122
145
it ( 'should run queued timer only once' , ( ) => {
123
146
fakeAsyncTestZone . run ( ( ) => {
124
147
let cycles = 0 ;
@@ -160,6 +183,9 @@ describe('FakeAsyncTestZoneSpec', () => {
160
183
161
184
testZoneSpec . tick ( 10 ) ;
162
185
expect ( cycles ) . toEqual ( 3 ) ;
186
+
187
+ testZoneSpec . tick ( 30 ) ;
188
+ expect ( cycles ) . toEqual ( 6 ) ;
163
189
} ) ;
164
190
} ) ;
165
191
You can’t perform that action at this time.
0 commit comments