@@ -14,6 +14,7 @@ describe('MatExpansionPanel', () => {
1414 ] ,
1515 declarations : [
1616 PanelWithContent ,
17+ PanelWithContentInNgIf ,
1718 PanelWithCustomMargin
1819 ] ,
1920 } ) ;
@@ -138,6 +139,16 @@ describe('MatExpansionPanel', () => {
138139 expect ( arrow . style . transform ) . toBe ( 'rotate(180deg)' , 'Expected 180 degree rotation.' ) ;
139140 } ) ) ;
140141
142+ it ( 'make sure accordion item runs ngOnDestroy when expansion panel is destroyed' , ( ) => {
143+ let fixture = TestBed . createComponent ( PanelWithContentInNgIf ) ;
144+ fixture . detectChanges ( ) ;
145+ let destroyedOk = false ;
146+ fixture . componentInstance . panel . destroyed . subscribe ( ( ) => destroyedOk = true ) ;
147+ fixture . componentInstance . expansionShown = false ;
148+ fixture . detectChanges ( ) ;
149+ expect ( destroyedOk ) . toBe ( true ) ;
150+ } ) ;
151+
141152 describe ( 'disabled state' , ( ) => {
142153 let fixture : ComponentFixture < PanelWithContent > ;
143154 let panel : HTMLElement ;
@@ -221,6 +232,18 @@ class PanelWithContent {
221232 @ViewChild ( MatExpansionPanel ) panel : MatExpansionPanel ;
222233}
223234
235+ @Component ( {
236+ template : `
237+ <div *ngIf="expansionShown">
238+ <mat-expansion-panel>
239+ <mat-expansion-panel-header>Panel Title</mat-expansion-panel-header>
240+ </mat-expansion-panel>
241+ </div>`
242+ } )
243+ class PanelWithContentInNgIf {
244+ expansionShown = true ;
245+ @ViewChild ( MatExpansionPanel ) panel : MatExpansionPanel ;
246+ }
224247
225248@Component ( {
226249 styles : [
0 commit comments