1+ import { ApplicationRef , Component } from '@angular/core' ;
12import { TestBed , inject } from '@angular/core/testing' ;
2- import { ApplicationRef , Component , afterRender } from '@angular/core' ;
3+ import { filter , take } from 'rxjs/operators' ;
4+ import { ComponentPortal } from '../../portal' ;
35import { dispatchFakeEvent , dispatchMouseEvent } from '../../testing/private' ;
4- import { OverlayModule , Overlay } from '../index' ;
6+ import { Overlay , OverlayModule } from '../index' ;
57import { OverlayOutsideClickDispatcher } from './overlay-outside-click-dispatcher' ;
6- import { ComponentPortal } from '../../portal' ;
7- import { filter , take } from 'rxjs/operators' ;
88
99describe ( 'OverlayOutsideClickDispatcher' , ( ) => {
1010 let appRef : ApplicationRef ;
@@ -388,11 +388,13 @@ describe('OverlayOutsideClickDispatcher', () => {
388388
389389 it ( 'should run change detection if the click was made outside the overlay and there are `outsidePointerEvents` observers' , async ( ) => {
390390 let renders = 0 ;
391- TestBed . runInInjectionContext ( ( ) => {
392- afterRender ( ( ) => {
391+ @Component ( { template : '{{increment()}}' } )
392+ class Counter {
393+ increment ( ) {
393394 renders ++ ;
394- } ) ;
395- } ) ;
395+ }
396+ }
397+ TestBed . createComponent ( Counter ) ;
396398 function stablePromise ( ) {
397399 return TestBed . inject ( ApplicationRef )
398400 . isStable . pipe (
@@ -402,7 +404,8 @@ describe('OverlayOutsideClickDispatcher', () => {
402404 . toPromise ( ) ;
403405 }
404406 await stablePromise ( ) ;
405- expect ( renders ) . toEqual ( 1 ) ;
407+ renders = 0 ;
408+ expect ( renders ) . toEqual ( 0 ) ;
406409 const portal = new ComponentPortal ( TestComponent ) ;
407410 const overlayRef = overlay . create ( ) ;
408411 overlayRef . attach ( portal ) ;
@@ -412,16 +415,16 @@ describe('OverlayOutsideClickDispatcher', () => {
412415 document . body . appendChild ( context ) ;
413416
414417 await stablePromise ( ) ;
415- expect ( renders ) . toEqual ( 2 ) ;
418+ expect ( renders ) . toEqual ( 1 ) ;
416419 dispatchMouseEvent ( context , 'click' ) ;
417420 await stablePromise ( ) ;
418- expect ( renders ) . toEqual ( 2 ) ;
421+ expect ( renders ) . toEqual ( 1 ) ;
419422
420423 overlayRef . outsidePointerEvents ( ) . subscribe ( ) ;
421424
422425 dispatchMouseEvent ( context , 'click' ) ;
423426 await stablePromise ( ) ;
424- expect ( renders ) . toEqual ( 2 ) ;
427+ expect ( renders ) . toEqual ( 1 ) ;
425428 } ) ;
426429 } ) ;
427430} ) ;
0 commit comments