@@ -11,8 +11,8 @@ describe('MatExpansionPanel', () => {
11
11
beforeEach ( async ( ( ) => {
12
12
TestBed . configureTestingModule ( {
13
13
imports : [
14
+ MatExpansionModule ,
14
15
NoopAnimationsModule ,
15
- MatExpansionModule
16
16
] ,
17
17
declarations : [
18
18
PanelWithContent ,
@@ -44,8 +44,9 @@ describe('MatExpansionPanel', () => {
44
44
} ) ) ;
45
45
46
46
it ( 'should be able to render panel content lazily' , fakeAsync ( ( ) => {
47
- let fixture = TestBed . createComponent ( LazyPanelWithContent ) ;
48
- let content = fixture . debugElement . query ( By . css ( '.mat-expansion-panel-content' ) ) . nativeElement ;
47
+ const fixture = TestBed . createComponent ( LazyPanelWithContent ) ;
48
+ const content = fixture . debugElement . query (
49
+ By . css ( '.mat-expansion-panel-content' ) ) . nativeElement ;
49
50
fixture . detectChanges ( ) ;
50
51
51
52
expect ( content . textContent . trim ( ) ) . toBe ( '' , 'Expected content element to be empty.' ) ;
@@ -58,8 +59,9 @@ describe('MatExpansionPanel', () => {
58
59
} ) ) ;
59
60
60
61
it ( 'should render the content for a lazy-loaded panel that is opened on init' , fakeAsync ( ( ) => {
61
- let fixture = TestBed . createComponent ( LazyPanelOpenOnLoad ) ;
62
- let content = fixture . debugElement . query ( By . css ( '.mat-expansion-panel-content' ) ) . nativeElement ;
62
+ const fixture = TestBed . createComponent ( LazyPanelOpenOnLoad ) ;
63
+ const content = fixture . debugElement . query (
64
+ By . css ( '.mat-expansion-panel-content' ) ) . nativeElement ;
63
65
fixture . detectChanges ( ) ;
64
66
65
67
expect ( content . textContent . trim ( ) )
@@ -161,10 +163,10 @@ describe('MatExpansionPanel', () => {
161
163
} ) ) ;
162
164
163
165
it ( 'should not override the panel margin if it is not inside an accordion' , fakeAsync ( ( ) => {
164
- let fixture = TestBed . createComponent ( PanelWithCustomMargin ) ;
166
+ const fixture = TestBed . createComponent ( PanelWithCustomMargin ) ;
165
167
fixture . detectChanges ( ) ;
166
168
167
- let panel = fixture . debugElement . query ( By . css ( 'mat-expansion-panel' ) ) ;
169
+ const panel = fixture . debugElement . query ( By . css ( 'mat-expansion-panel' ) ) ;
168
170
let styles = getComputedStyle ( panel . nativeElement ) ;
169
171
170
172
expect ( panel . componentInstance . _hasSpacing ( ) ) . toBe ( false ) ;
@@ -221,7 +223,7 @@ describe('MatExpansionPanel', () => {
221
223
} ) ) ;
222
224
223
225
it ( 'should make sure accordion item runs ngOnDestroy when expansion panel is destroyed' , ( ) => {
224
- let fixture = TestBed . createComponent ( PanelWithContentInNgIf ) ;
226
+ const fixture = TestBed . createComponent ( PanelWithContentInNgIf ) ;
225
227
fixture . detectChanges ( ) ;
226
228
let destroyedOk = false ;
227
229
fixture . componentInstance . panel . destroyed . subscribe ( ( ) => destroyedOk = true ) ;
@@ -264,6 +266,35 @@ describe('MatExpansionPanel', () => {
264
266
'Expected class to be added after the animation has finished' ) ;
265
267
} ) ) ;
266
268
269
+ it ( 'should emit events for body expanding and collapsing animations' , fakeAsync ( ( ) => {
270
+ const fixture = TestBed . createComponent ( PanelWithContent ) ;
271
+ fixture . detectChanges ( ) ;
272
+ let beforeExpand = 0 ;
273
+ let afterExpand = 0 ;
274
+ let beforeCollaps = 0 ;
275
+ let afterCollaps = 0 ;
276
+ fixture . componentInstance . panel . beforeExpand . subscribe ( ( ) => beforeExpand ++ ) ;
277
+ fixture . componentInstance . panel . afterExpand . subscribe ( ( ) => afterExpand ++ ) ;
278
+ fixture . componentInstance . panel . beforeCollapse . subscribe ( ( ) => beforeCollaps ++ ) ;
279
+ fixture . componentInstance . panel . afterCollapse . subscribe ( ( ) => afterCollaps ++ ) ;
280
+
281
+ fixture . componentInstance . expanded = true ;
282
+ fixture . detectChanges ( ) ;
283
+ flush ( ) ;
284
+ expect ( beforeExpand ) . toBe ( 1 ) ;
285
+ expect ( afterExpand ) . toBe ( 1 ) ;
286
+ expect ( beforeCollaps ) . toBe ( 0 ) ;
287
+ expect ( afterCollaps ) . toBe ( 0 ) ;
288
+
289
+ fixture . componentInstance . expanded = false ;
290
+ fixture . detectChanges ( ) ;
291
+ flush ( ) ;
292
+ expect ( beforeExpand ) . toBe ( 1 ) ;
293
+ expect ( afterExpand ) . toBe ( 1 ) ;
294
+ expect ( beforeCollaps ) . toBe ( 1 ) ;
295
+ expect ( afterCollaps ) . toBe ( 1 ) ;
296
+ } ) ) ;
297
+
267
298
describe ( 'disabled state' , ( ) => {
268
299
let fixture : ComponentFixture < PanelWithContent > ;
269
300
let panel : HTMLElement ;
@@ -373,7 +404,7 @@ class PanelWithContentInNgIf {
373
404
</mat-expansion-panel>`
374
405
} )
375
406
class PanelWithCustomMargin {
376
- expanded : boolean = false ;
407
+ expanded = false ;
377
408
}
378
409
379
410
@Component ( {
0 commit comments