@@ -167,6 +167,23 @@ describe('Overlay directives', () => {
167167 `Expected directive to emit an instance of ConnectedOverlayPositionChange.` ) ;
168168 } ) ;
169169
170+ it ( 'should emit attach and detach appropriately' , ( ) => {
171+ expect ( fixture . componentInstance . attachHandler ) . not . toHaveBeenCalled ( ) ;
172+ expect ( fixture . componentInstance . detachHandler ) . not . toHaveBeenCalled ( ) ;
173+ fixture . componentInstance . isOpen = true ;
174+ fixture . detectChanges ( ) ;
175+
176+ expect ( fixture . componentInstance . attachHandler ) . toHaveBeenCalled ( ) ;
177+ expect ( fixture . componentInstance . attachResult )
178+ . toEqual ( jasmine . any ( HTMLElement ) ,
179+ `Expected pane to be populated with HTML elements when attach was called.` ) ;
180+ expect ( fixture . componentInstance . detachHandler ) . not . toHaveBeenCalled ( ) ;
181+
182+ fixture . componentInstance . isOpen = false ;
183+ fixture . detectChanges ( ) ;
184+ expect ( fixture . componentInstance . detachHandler ) . toHaveBeenCalled ( ) ;
185+ } ) ;
186+
170187 } ) ;
171188
172189} ) ;
@@ -178,7 +195,8 @@ describe('Overlay directives', () => {
178195 <template connected-overlay [origin]="trigger" [open]="isOpen" [width]="width" [height]="height"
179196 [hasBackdrop]="hasBackdrop" backdropClass="md-test-class"
180197 (backdropClick)="backdropClicked=true" [offsetX]="offsetX" [offsetY]="offsetY"
181- (positionChange)="positionChangeHandler($event)">
198+ (positionChange)="positionChangeHandler($event)" (attach)="attachHandler()"
199+ (detach)="detachHandler()">
182200 <p>Menu content</p>
183201 </template>` ,
184202} )
@@ -191,6 +209,12 @@ class ConnectedOverlayDirectiveTest {
191209 hasBackdrop : boolean ;
192210 backdropClicked = false ;
193211 positionChangeHandler = jasmine . createSpy ( 'positionChangeHandler' ) ;
212+ attachHandler = jasmine . createSpy ( 'attachHandler' ) . and . callFake ( ( ) => {
213+ this . attachResult =
214+ this . connectedOverlayDirective . overlayRef . overlayElement . querySelector ( 'p' ) as HTMLElement ;
215+ } ) ;
216+ detachHandler = jasmine . createSpy ( 'detachHandler' ) ;
217+ attachResult : HTMLElement ;
194218
195219 @ViewChild ( ConnectedOverlayDirective ) connectedOverlayDirective : ConnectedOverlayDirective ;
196220}
0 commit comments