1
+ import { ApplicationRef , Component } from '@angular/core' ;
1
2
import { 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' ;
3
5
import { dispatchFakeEvent , dispatchMouseEvent } from '../../testing/private' ;
4
- import { OverlayModule , Overlay } from '../index' ;
6
+ import { Overlay , OverlayModule } from '../index' ;
5
7
import { OverlayOutsideClickDispatcher } from './overlay-outside-click-dispatcher' ;
6
- import { ComponentPortal } from '../../portal' ;
7
- import { filter , take } from 'rxjs/operators' ;
8
8
9
9
describe ( 'OverlayOutsideClickDispatcher' , ( ) => {
10
10
let appRef : ApplicationRef ;
@@ -388,11 +388,13 @@ describe('OverlayOutsideClickDispatcher', () => {
388
388
389
389
it ( 'should run change detection if the click was made outside the overlay and there are `outsidePointerEvents` observers' , async ( ) => {
390
390
let renders = 0 ;
391
- TestBed . runInInjectionContext ( ( ) => {
392
- afterRender ( ( ) => {
391
+ @Component ( { template : '{{increment()}}' } )
392
+ class Counter {
393
+ increment ( ) {
393
394
renders ++ ;
394
- } ) ;
395
- } ) ;
395
+ }
396
+ }
397
+ TestBed . createComponent ( Counter ) ;
396
398
function stablePromise ( ) {
397
399
return TestBed . inject ( ApplicationRef )
398
400
. isStable . pipe (
@@ -402,7 +404,8 @@ describe('OverlayOutsideClickDispatcher', () => {
402
404
. toPromise ( ) ;
403
405
}
404
406
await stablePromise ( ) ;
405
- expect ( renders ) . toEqual ( 1 ) ;
407
+ renders = 0 ;
408
+ expect ( renders ) . toEqual ( 0 ) ;
406
409
const portal = new ComponentPortal ( TestComponent ) ;
407
410
const overlayRef = overlay . create ( ) ;
408
411
overlayRef . attach ( portal ) ;
@@ -412,16 +415,16 @@ describe('OverlayOutsideClickDispatcher', () => {
412
415
document . body . appendChild ( context ) ;
413
416
414
417
await stablePromise ( ) ;
415
- expect ( renders ) . toEqual ( 2 ) ;
418
+ expect ( renders ) . toEqual ( 1 ) ;
416
419
dispatchMouseEvent ( context , 'click' ) ;
417
420
await stablePromise ( ) ;
418
- expect ( renders ) . toEqual ( 2 ) ;
421
+ expect ( renders ) . toEqual ( 1 ) ;
419
422
420
423
overlayRef . outsidePointerEvents ( ) . subscribe ( ) ;
421
424
422
425
dispatchMouseEvent ( context , 'click' ) ;
423
426
await stablePromise ( ) ;
424
- expect ( renders ) . toEqual ( 2 ) ;
427
+ expect ( renders ) . toEqual ( 1 ) ;
425
428
} ) ;
426
429
} ) ;
427
430
} ) ;
0 commit comments