@@ -75,21 +75,21 @@ describe('MatSnackBar', () => {
75
75
. toBe ( 'alert' , 'Expected snack bar container to have role="alert"' ) ;
76
76
} ) ;
77
77
78
- it ( 'should open and close a snackbar without a ViewContainerRef' , fakeAsync ( ( ) => {
79
- let snackBarRef = snackBar . open ( 'Snack time!' , 'Chew' ) ;
80
- viewContainerFixture . detectChanges ( ) ;
78
+ it ( 'should open and close a snackbar without a ViewContainerRef' , fakeAsync ( ( ) => {
79
+ let snackBarRef = snackBar . open ( 'Snack time!' , 'Chew' ) ;
80
+ viewContainerFixture . detectChanges ( ) ;
81
81
82
- let messageElement = overlayContainerElement . querySelector ( 'snack-bar-container' ) ! ;
83
- expect ( messageElement . textContent ) . toContain ( 'Snack time!' ,
84
- 'Expected snack bar to show a message without a ViewContainerRef' ) ;
82
+ let messageElement = overlayContainerElement . querySelector ( 'snack-bar-container' ) ! ;
83
+ expect ( messageElement . textContent ) . toContain ( 'Snack time!' ,
84
+ 'Expected snack bar to show a message without a ViewContainerRef' ) ;
85
85
86
- snackBarRef . dismiss ( ) ;
87
- viewContainerFixture . detectChanges ( ) ;
88
- flush ( ) ;
86
+ snackBarRef . dismiss ( ) ;
87
+ viewContainerFixture . detectChanges ( ) ;
88
+ flush ( ) ;
89
89
90
- expect ( overlayContainerElement . childNodes . length )
91
- . toBe ( 0 , 'Expected snack bar to be dismissed without a ViewContainerRef' ) ;
92
- } ) ) ;
90
+ expect ( overlayContainerElement . childNodes . length )
91
+ . toBe ( 0 , 'Expected snack bar to be dismissed without a ViewContainerRef' ) ;
92
+ } ) ) ;
93
93
94
94
it ( 'should open a simple message with a button' , ( ) => {
95
95
let config : MatSnackBarConfig = { viewContainerRef : testViewContainerRef } ;
@@ -153,6 +153,36 @@ describe('MatSnackBar', () => {
153
153
. toBe ( 0 , 'Expected the overlay container element to have no child elements' ) ;
154
154
} ) ) ;
155
155
156
+
157
+ it ( 'should default to the passed message for the announcement message' , fakeAsync ( ( ) => {
158
+ spyOn ( liveAnnouncer , 'announce' ) ;
159
+
160
+ snackBar . open ( simpleMessage ) ;
161
+ viewContainerFixture . detectChanges ( ) ;
162
+
163
+ expect ( overlayContainerElement . childElementCount )
164
+ . toBe ( 1 , 'Expected the overlay with the default announcement message to be added' ) ;
165
+
166
+ // Expect the live announcer to have been called with the display message and some
167
+ // string for the politeness. We do not want to test for the default politeness here.
168
+ expect ( liveAnnouncer . announce ) . toHaveBeenCalledWith ( simpleMessage , jasmine . any ( String ) ) ;
169
+ } ) ) ;
170
+
171
+ it ( 'should be able to specify a custom announcement message' , fakeAsync ( ( ) => {
172
+ spyOn ( liveAnnouncer , 'announce' ) ;
173
+
174
+ snackBar . open ( simpleMessage , '' , {
175
+ announcementMessage : 'Custom announcement' ,
176
+ politeness : 'assertive'
177
+ } ) ;
178
+ viewContainerFixture . detectChanges ( ) ;
179
+
180
+ expect ( overlayContainerElement . childElementCount )
181
+ . toBe ( 1 , 'Expected the overlay with a custom `announcementMessage` to be added' ) ;
182
+
183
+ expect ( liveAnnouncer . announce ) . toHaveBeenCalledWith ( 'Custom announcement' , 'assertive' ) ;
184
+ } ) ) ;
185
+
156
186
it ( 'should be able to get dismissed through the service' , fakeAsync ( ( ) => {
157
187
snackBar . open ( simpleMessage ) ;
158
188
viewContainerFixture . detectChanges ( ) ;
0 commit comments