@@ -18,6 +18,7 @@ describe('MatExpansionPanel', () => {
1818 PanelWithCustomMargin ,
1919 LazyPanelWithContent ,
2020 LazyPanelOpenOnLoad ,
21+ PanelWithTwoWayBinding ,
2122 ] ,
2223 } ) ;
2324 TestBed . compileComponents ( ) ;
@@ -165,15 +166,31 @@ describe('MatExpansionPanel', () => {
165166 expect ( arrow . style . transform ) . toBe ( 'rotate(180deg)' , 'Expected 180 degree rotation.' ) ;
166167 } ) ) ;
167168
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+ } ) ;
177194
178195 describe ( 'disabled state' , ( ) => {
179196 let fixture : ComponentFixture < PanelWithContent > ;
@@ -313,3 +330,14 @@ class LazyPanelWithContent {
313330 </mat-expansion-panel>`
314331} )
315332class 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