@@ -452,6 +452,18 @@ describe('MatSnackBar', () => {
452452 . toContain ( 'custom-class' , 'Expected class applied through the defaults to be applied.' ) ;
453453 } ) ) ;
454454
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+
455467 describe ( 'with custom component' , ( ) => {
456468 it ( 'should open a custom component' , ( ) => {
457469 const snackBarRef = snackBar . openFromComponent ( BurritosNotification ) ;
@@ -603,6 +615,18 @@ describe('MatSnackBar with parent MatSnackBar', () => {
603615 expect ( overlayContainerElement . textContent )
604616 . toContain ( 'Taco' , 'Expected child snackbar msg to be dismissed by opening from parent' ) ;
605617 } ) ) ;
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+ } ) ) ;
606630} ) ;
607631
608632describe ( 'MatSnackBar Positioning' , ( ) => {
0 commit comments