This repository was archived by the owner on Feb 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5151 }
5252
5353 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 ) {
5656 let current = this . _schedulerQueue [ 0 ] ;
57- if ( this . _currentTime < current . endTime ) {
57+ if ( finalTime < current . endTime ) {
5858 // Done processing the queue since it's sorted by endTime.
5959 break ;
6060 } else {
6161 // Time to run scheduled function. Remove it from the head of queue.
6262 let current = this . _schedulerQueue . shift ( ) ;
63+ this . _currentTime = current . endTime ;
6364 let retval = current . func . apply ( global , current . args ) ;
6465 if ( ! retval ) {
6566 // Uncaught exception in the current scheduled function. Stop processing the queue.
6667 break ;
6768 }
6869 }
6970 }
71+ this . _currentTime = finalTime ;
7072 }
7173 }
7274
Original file line number Diff line number Diff line change @@ -119,6 +119,29 @@ describe('FakeAsyncTestZoneSpec', () => {
119119 } ) ;
120120 } ) ;
121121
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+
122145 it ( 'should run queued timer only once' , ( ) => {
123146 fakeAsyncTestZone . run ( ( ) => {
124147 let cycles = 0 ;
@@ -160,6 +183,9 @@ describe('FakeAsyncTestZoneSpec', () => {
160183
161184 testZoneSpec . tick ( 10 ) ;
162185 expect ( cycles ) . toEqual ( 3 ) ;
186+
187+ testZoneSpec . tick ( 30 ) ;
188+ expect ( cycles ) . toEqual ( 6 ) ;
163189 } ) ;
164190 } ) ;
165191
You can’t perform that action at this time.
0 commit comments