@@ -14,6 +14,7 @@ describe('MatExpansionPanel', () => {
14
14
] ,
15
15
declarations : [
16
16
PanelWithContent ,
17
+ PanelWithContentInNgIf ,
17
18
PanelWithCustomMargin
18
19
] ,
19
20
} ) ;
@@ -138,6 +139,16 @@ describe('MatExpansionPanel', () => {
138
139
expect ( arrow . style . transform ) . toBe ( 'rotate(180deg)' , 'Expected 180 degree rotation.' ) ;
139
140
} ) ) ;
140
141
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
+
141
152
describe ( 'disabled state' , ( ) => {
142
153
let fixture : ComponentFixture < PanelWithContent > ;
143
154
let panel : HTMLElement ;
@@ -221,6 +232,18 @@ class PanelWithContent {
221
232
@ViewChild ( MatExpansionPanel ) panel : MatExpansionPanel ;
222
233
}
223
234
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
+ }
224
247
225
248
@Component ( {
226
249
styles : [
0 commit comments