@@ -502,7 +502,7 @@ describe('FakeAsyncTestZoneSpec', () => {
502502 'flush failed after reaching the limit of 20 tasks. Does your code use a polling timeout?' ) ;
503503 } ) ;
504504
505- it ( 'accepts a custom limit' , function ( ) {
505+ it ( 'accepts a custom limit' , ( ) => {
506506 expect ( ( ) => {
507507 fakeAsyncTestZone . run ( ( ) => {
508508 let z = 0 ;
@@ -521,6 +521,42 @@ describe('FakeAsyncTestZoneSpec', () => {
521521 . toThrowError (
522522 'flush failed after reaching the limit of 10 tasks. Does your code use a polling timeout?' ) ;
523523 } ) ;
524+
525+ it ( 'can flush periodic timers if flushPeriodic is true' , ( ) => {
526+ fakeAsyncTestZone . run ( ( ) => {
527+ let x = 0 ;
528+
529+ setInterval ( ( ) => {
530+ x ++ ;
531+ } , 10 ) ;
532+
533+ let elapsed = testZoneSpec . flush ( 20 , true ) ;
534+
535+ expect ( elapsed ) . toEqual ( 10 ) ;
536+ expect ( x ) . toEqual ( 1 ) ;
537+ } ) ;
538+ } ) ;
539+
540+ it ( 'can flush multiple periodic timers if flushPeriodic is true' , ( ) => {
541+ fakeAsyncTestZone . run ( ( ) => {
542+ let x = 0 ;
543+ let y = 0 ;
544+
545+ setInterval ( ( ) => {
546+ x ++ ;
547+ } , 10 ) ;
548+
549+ setInterval ( ( ) => {
550+ y ++ ;
551+ } , 100 ) ;
552+
553+ let elapsed = testZoneSpec . flush ( 20 , true ) ;
554+
555+ expect ( elapsed ) . toEqual ( 100 ) ;
556+ expect ( x ) . toEqual ( 10 ) ;
557+ expect ( y ) . toEqual ( 1 ) ;
558+ } ) ;
559+ } ) ;
524560 } ) ;
525561
526562 describe ( 'outside of FakeAsync Zone' , ( ) => {
@@ -578,6 +614,27 @@ describe('FakeAsyncTestZoneSpec', () => {
578614 expect ( ran ) . toEqual ( false ) ;
579615 } ) ;
580616 } ) ;
617+ it ( 'is not flushed when flushPeriodic is false' , ( ) => {
618+ let ran = false ;
619+ fakeAsyncTestZone . run ( ( ) => {
620+ requestAnimationFrame ( ( ) => {
621+ ran = true ;
622+ } ) ;
623+ testZoneSpec . flush ( 20 ) ;
624+ expect ( ran ) . toEqual ( false ) ;
625+ } ) ;
626+ } ) ;
627+ it ( 'is flushed when flushPeriodic is true' , ( ) => {
628+ let ran = false ;
629+ fakeAsyncTestZone . run ( ( ) => {
630+ requestAnimationFrame ( ( ) => {
631+ ran = true ;
632+ } ) ;
633+ const elapsed = testZoneSpec . flush ( 20 , true ) ;
634+ expect ( elapsed ) . toEqual ( 16 ) ;
635+ expect ( ran ) . toEqual ( true ) ;
636+ } ) ;
637+ } ) ;
581638 } ) ) ;
582639 } ) ;
583640 } ) ;
0 commit comments