@@ -74,13 +74,29 @@ export class MatSnackBarHarness extends ComponentHarness {
74
74
return ( await this . _simpleSnackBarMessage ( ) ) . text ( ) ;
75
75
}
76
76
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 ( 'mat-exit' ) ,
87
+ host . getDimensions ( ) ,
88
+ ] ) ;
89
+
90
+ return exit != null || ( ! ! dimensions && dimensions . height === 0 && dimensions . width === 0 ) ;
91
+ }
92
+
77
93
/**
78
94
* Asserts that the current snack-bar does not use custom content. Promise rejects if
79
95
* custom content is used.
80
96
*/
81
97
private async _assertSimpleSnackBar ( ) : Promise < void > {
82
98
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.' ) ;
84
100
}
85
101
}
86
102
@@ -91,7 +107,7 @@ export class MatSnackBarHarness extends ComponentHarness {
91
107
private async _assertSimpleSnackBarWithAction ( ) : Promise < void > {
92
108
await this . _assertSimpleSnackBar ( ) ;
93
109
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.' ) ;
95
111
}
96
112
}
97
113
0 commit comments