@@ -18,6 +18,7 @@ describe('MatExpansionPanel', () => {
18
18
PanelWithCustomMargin ,
19
19
LazyPanelWithContent ,
20
20
LazyPanelOpenOnLoad ,
21
+ PanelWithTwoWayBinding ,
21
22
] ,
22
23
} ) ;
23
24
TestBed . compileComponents ( ) ;
@@ -165,15 +166,31 @@ describe('MatExpansionPanel', () => {
165
166
expect ( arrow . style . transform ) . toBe ( 'rotate(180deg)' , 'Expected 180 degree rotation.' ) ;
166
167
} ) ) ;
167
168
168
- it ( 'make sure accordion item runs ngOnDestroy when expansion panel is destroyed' , ( ) => {
169
- let fixture = TestBed . createComponent ( PanelWithContentInNgIf ) ;
170
- fixture . detectChanges ( ) ;
171
- let destroyedOk = false ;
172
- fixture . componentInstance . panel . destroyed . subscribe ( ( ) => destroyedOk = true ) ;
173
- fixture . componentInstance . expansionShown = false ;
174
- fixture . detectChanges ( ) ;
175
- expect ( destroyedOk ) . toBe ( true ) ;
176
- } ) ;
169
+ it ( 'should make sure accordion item runs ngOnDestroy when expansion panel is destroyed' , ( ) => {
170
+ let fixture = TestBed . createComponent ( PanelWithContentInNgIf ) ;
171
+ fixture . detectChanges ( ) ;
172
+ let destroyedOk = false ;
173
+ fixture . componentInstance . panel . destroyed . subscribe ( ( ) => destroyedOk = true ) ;
174
+ fixture . componentInstance . expansionShown = false ;
175
+ fixture . detectChanges ( ) ;
176
+ expect ( destroyedOk ) . toBe ( true ) ;
177
+ } ) ;
178
+
179
+ it ( 'should support two-way binding of the `expanded` property' , ( ) => {
180
+ const fixture = TestBed . createComponent ( PanelWithTwoWayBinding ) ;
181
+ const header = fixture . debugElement . query ( By . css ( 'mat-expansion-panel-header' ) ) . nativeElement ;
182
+
183
+ fixture . detectChanges ( ) ;
184
+ expect ( fixture . componentInstance . expanded ) . toBe ( false ) ;
185
+
186
+ header . click ( ) ;
187
+ fixture . detectChanges ( ) ;
188
+ expect ( fixture . componentInstance . expanded ) . toBe ( true ) ;
189
+
190
+ header . click ( ) ;
191
+ fixture . detectChanges ( ) ;
192
+ expect ( fixture . componentInstance . expanded ) . toBe ( false ) ;
193
+ } ) ;
177
194
178
195
describe ( 'disabled state' , ( ) => {
179
196
let fixture : ComponentFixture < PanelWithContent > ;
@@ -313,3 +330,14 @@ class LazyPanelWithContent {
313
330
</mat-expansion-panel>`
314
331
} )
315
332
class LazyPanelOpenOnLoad { }
333
+
334
+
335
+ @Component ( {
336
+ template : `
337
+ <mat-expansion-panel [(expanded)]="expanded">
338
+ <mat-expansion-panel-header>Panel Title</mat-expansion-panel-header>
339
+ </mat-expansion-panel>`
340
+ } )
341
+ class PanelWithTwoWayBinding {
342
+ expanded = false ;
343
+ }
0 commit comments