@@ -74,13 +74,29 @@ export class MatSnackBarHarness extends ComponentHarness {
7474 return ( await this . _simpleSnackBarMessage ( ) ) . text ( ) ;
7575 }
7676
77+ /** Gets whether the snack-bar has been dismissed. */
78+ async isDismissed ( ) : Promise < boolean > {
79+ // We consider the snackbar dismissed if it's not in the DOM. We can assert that the
80+ // element isn't in the DOM by seeing that its width and height are zero.
81+
82+ const host = await this . host ( ) ;
83+ const [ exit , dimensions ] = await Promise . all ( [
84+ // The snackbar container is marked with the "exit" attribute after it has been dismissed
85+ // but before the animation has finished (after which it's removed from the DOM).
86+ host . getAttribute ( 'exit' ) ,
87+ host . getDimensions ( ) ,
88+ ] ) ;
89+
90+ return exit != null || ( ! ! dimensions && dimensions . height === 0 && dimensions . width === 0 ) ;
91+ }
92+
7793 /**
7894 * Asserts that the current snack-bar does not use custom content. Promise rejects if
7995 * custom content is used.
8096 */
8197 private async _assertSimpleSnackBar ( ) : Promise < void > {
8298 if ( ! await this . _isSimpleSnackBar ( ) ) {
83- throw new Error ( 'Method cannot be used for snack-bar with custom content.' ) ;
99+ throw Error ( 'Method cannot be used for snack-bar with custom content.' ) ;
84100 }
85101 }
86102
@@ -91,7 +107,7 @@ export class MatSnackBarHarness extends ComponentHarness {
91107 private async _assertSimpleSnackBarWithAction ( ) : Promise < void > {
92108 await this . _assertSimpleSnackBar ( ) ;
93109 if ( ! await this . hasAction ( ) ) {
94- throw new Error ( 'Method cannot be used for standard snack-bar without action.' ) ;
110+ throw Error ( 'Method cannot be used for standard snack-bar without action.' ) ;
95111 }
96112 }
97113
0 commit comments