1
+ import { ApplicationRef , Component , NgZone } from '@angular/core' ;
1
2
import { TestBed , inject } from '@angular/core/testing' ;
2
- import { ApplicationRef , Component , afterRender } from '@angular/core ' ;
3
+ import { ComponentPortal } from '../../portal ' ;
3
4
import { dispatchFakeEvent , dispatchMouseEvent } from '../../testing/private' ;
4
- import { OverlayModule , Overlay } from '../index' ;
5
+ import { Overlay , OverlayModule } from '../index' ;
5
6
import { OverlayOutsideClickDispatcher } from './overlay-outside-click-dispatcher' ;
6
- import { ComponentPortal } from '../../portal' ;
7
- import { filter , take } from 'rxjs/operators' ;
8
7
9
8
describe ( 'OverlayOutsideClickDispatcher' , ( ) => {
10
9
let appRef : ApplicationRef ;
@@ -386,23 +385,12 @@ describe('OverlayOutsideClickDispatcher', () => {
386
385
expect ( appRef . tick ) . toHaveBeenCalledTimes ( 0 ) ;
387
386
} ) ;
388
387
389
- it ( 'should run change detection if the click was made outside the overlay and there are `outsidePointerEvents` observers' , async ( ) => {
390
- let renders = 0 ;
391
- TestBed . runInInjectionContext ( ( ) => {
392
- afterRender ( ( ) => {
393
- renders ++ ;
394
- } ) ;
395
- } ) ;
396
- function stablePromise ( ) {
397
- return TestBed . inject ( ApplicationRef )
398
- . isStable . pipe (
399
- filter ( stable => stable ) ,
400
- take ( 1 ) ,
401
- )
402
- . toPromise ( ) ;
403
- }
404
- await stablePromise ( ) ;
405
- expect ( renders ) . toEqual ( 1 ) ;
388
+ it ( 'should emit `outsidePointerEvents` outside NgZone' , async ( ) => {
389
+ const calls : boolean [ ] = [ ] ;
390
+ const spy = ( ) => {
391
+ calls . push ( NgZone . isInAngularZone ( ) ) ;
392
+ } ;
393
+
406
394
const portal = new ComponentPortal ( TestComponent ) ;
407
395
const overlayRef = overlay . create ( ) ;
408
396
overlayRef . attach ( portal ) ;
@@ -411,17 +399,11 @@ describe('OverlayOutsideClickDispatcher', () => {
411
399
const context = document . createElement ( 'div' ) ;
412
400
document . body . appendChild ( context ) ;
413
401
414
- await stablePromise ( ) ;
415
- expect ( renders ) . toEqual ( 2 ) ;
416
- dispatchMouseEvent ( context , 'click' ) ;
417
- await stablePromise ( ) ;
418
- expect ( renders ) . toEqual ( 2 ) ;
419
-
420
- overlayRef . outsidePointerEvents ( ) . subscribe ( ) ;
402
+ overlayRef . outsidePointerEvents ( ) . subscribe ( spy ) ;
421
403
422
404
dispatchMouseEvent ( context , 'click' ) ;
423
- await stablePromise ( ) ;
424
- expect ( renders ) . toEqual ( 2 ) ;
405
+ await TestBed . inject ( ApplicationRef ) . whenStable ( ) ;
406
+ expect ( calls ) . toEqual ( [ false ] ) ;
425
407
} ) ;
426
408
} ) ;
427
409
} ) ;
0 commit comments