@@ -452,6 +452,18 @@ describe('MatSnackBar', () => {
452
452
. toContain ( 'custom-class' , 'Expected class applied through the defaults to be applied.' ) ;
453
453
} ) ) ;
454
454
455
+ it ( 'should dismiss the open snack bar on destroy' , fakeAsync ( ( ) => {
456
+ snackBar . open ( simpleMessage ) ;
457
+ viewContainerFixture . detectChanges ( ) ;
458
+ expect ( overlayContainerElement . childElementCount ) . toBeGreaterThan ( 0 ) ;
459
+
460
+ snackBar . ngOnDestroy ( ) ;
461
+ viewContainerFixture . detectChanges ( ) ;
462
+ flush ( ) ;
463
+
464
+ expect ( overlayContainerElement . childElementCount ) . toBe ( 0 ) ;
465
+ } ) ) ;
466
+
455
467
describe ( 'with custom component' , ( ) => {
456
468
it ( 'should open a custom component' , ( ) => {
457
469
const snackBarRef = snackBar . openFromComponent ( BurritosNotification ) ;
@@ -603,6 +615,18 @@ describe('MatSnackBar with parent MatSnackBar', () => {
603
615
expect ( overlayContainerElement . textContent )
604
616
. toContain ( 'Taco' , 'Expected child snackbar msg to be dismissed by opening from parent' ) ;
605
617
} ) ) ;
618
+
619
+ it ( 'should not dismiss parent snack bar if child is destroyed' , fakeAsync ( ( ) => {
620
+ parentSnackBar . open ( 'Pizza' ) ;
621
+ fixture . detectChanges ( ) ;
622
+ expect ( overlayContainerElement . childElementCount ) . toBeGreaterThan ( 0 ) ;
623
+
624
+ childSnackBar . ngOnDestroy ( ) ;
625
+ fixture . detectChanges ( ) ;
626
+ flush ( ) ;
627
+
628
+ expect ( overlayContainerElement . childElementCount ) . toBeGreaterThan ( 0 ) ;
629
+ } ) ) ;
606
630
} ) ;
607
631
608
632
describe ( 'MatSnackBar Positioning' , ( ) => {
0 commit comments