1+ import { ApplicationRef , Component , NgZone } from '@angular/core' ;
12import { TestBed , inject } from '@angular/core/testing' ;
2- import { ApplicationRef , Component , afterRender } from '@angular/core ' ;
3+ import { ComponentPortal } from '../../portal ' ;
34import { dispatchFakeEvent , dispatchMouseEvent } from '../../testing/private' ;
4- import { OverlayModule , Overlay } from '../index' ;
5+ import { Overlay , OverlayModule } from '../index' ;
56import { OverlayOutsideClickDispatcher } from './overlay-outside-click-dispatcher' ;
6- import { ComponentPortal } from '../../portal' ;
7- import { filter , take } from 'rxjs/operators' ;
87
98describe ( 'OverlayOutsideClickDispatcher' , ( ) => {
109 let appRef : ApplicationRef ;
@@ -386,23 +385,12 @@ describe('OverlayOutsideClickDispatcher', () => {
386385 expect ( appRef . tick ) . toHaveBeenCalledTimes ( 0 ) ;
387386 } ) ;
388387
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+
406394 const portal = new ComponentPortal ( TestComponent ) ;
407395 const overlayRef = overlay . create ( ) ;
408396 overlayRef . attach ( portal ) ;
@@ -411,17 +399,11 @@ describe('OverlayOutsideClickDispatcher', () => {
411399 const context = document . createElement ( 'div' ) ;
412400 document . body . appendChild ( context ) ;
413401
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 ) ;
421403
422404 dispatchMouseEvent ( context , 'click' ) ;
423- await stablePromise ( ) ;
424- expect ( renders ) . toEqual ( 2 ) ;
405+ await TestBed . inject ( ApplicationRef ) . whenStable ( ) ;
406+ expect ( calls ) . toEqual ( [ false ] ) ;
425407 } ) ;
426408 } ) ;
427409} ) ;
0 commit comments