@@ -128,22 +128,20 @@ describe('MatSnackBar', () => {
128
128
129
129
it ( 'should dismiss the snack bar and remove itself from the view' , async ( ( ) => {
130
130
let config : MatSnackBarConfig = { viewContainerRef : testViewContainerRef } ;
131
- let dismissObservableCompleted = false ;
131
+ let dismissCompleteSpy = jasmine . createSpy ( 'dismiss complete spy' ) ;
132
132
133
133
let snackBarRef = snackBar . open ( simpleMessage , undefined , config ) ;
134
134
viewContainerFixture . detectChanges ( ) ;
135
135
expect ( overlayContainerElement . childElementCount )
136
136
. toBeGreaterThan ( 0 , 'Expected overlay container element to have at least one child' ) ;
137
137
138
- snackBarRef . afterDismissed ( ) . subscribe ( undefined , undefined , ( ) => {
139
- dismissObservableCompleted = true ;
140
- } ) ;
138
+ snackBarRef . afterDismissed ( ) . subscribe ( undefined , undefined , dismissCompleteSpy ) ;
141
139
142
140
snackBarRef . dismiss ( ) ;
143
141
viewContainerFixture . detectChanges ( ) ; // Run through animations for dismissal
144
142
145
143
viewContainerFixture . whenStable ( ) . then ( ( ) => {
146
- expect ( dismissObservableCompleted ) . toBeTruthy ( 'Expected the snack bar to be dismissed' ) ;
144
+ expect ( dismissCompleteSpy ) . toHaveBeenCalled ( ) ;
147
145
expect ( overlayContainerElement . childElementCount )
148
146
. toBe ( 0 , 'Expected the overlay container element to have no child elements' ) ;
149
147
} ) ;
@@ -204,7 +202,7 @@ describe('MatSnackBar', () => {
204
202
state to visible on entry of new snack bar` , async ( ( ) => {
205
203
let config : MatSnackBarConfig = { viewContainerRef : testViewContainerRef } ;
206
204
let snackBarRef = snackBar . open ( simpleMessage , undefined , config ) ;
207
- let dismissObservableCompleted = false ;
205
+ let dismissCompleteSpy = jasmine . createSpy ( 'dismiss complete spy' ) ;
208
206
209
207
viewContainerFixture . detectChanges ( ) ;
210
208
expect ( snackBarRef . containerInstance . _animationState )
@@ -214,12 +212,10 @@ describe('MatSnackBar', () => {
214
212
let snackBarRef2 = snackBar . open ( simpleMessage , undefined , config2 ) ;
215
213
216
214
viewContainerFixture . detectChanges ( ) ;
217
- snackBarRef . afterDismissed ( ) . subscribe ( undefined , undefined , ( ) => {
218
- dismissObservableCompleted = true ;
219
- } ) ;
215
+ snackBarRef . afterDismissed ( ) . subscribe ( undefined , undefined , dismissCompleteSpy ) ;
220
216
221
217
viewContainerFixture . whenStable ( ) . then ( ( ) => {
222
- expect ( dismissObservableCompleted ) . toBe ( true ) ;
218
+ expect ( dismissCompleteSpy ) . toHaveBeenCalled ( ) ;
223
219
expect ( snackBarRef . containerInstance . _animationState )
224
220
. toBe ( 'hidden-bottom' , `Expected the animation state would be 'hidden-bottom'.` ) ;
225
221
expect ( snackBarRef2 . containerInstance . _animationState )
@@ -282,70 +278,75 @@ describe('MatSnackBar', () => {
282
278
283
279
it ( 'should dismiss the snackbar when the action is called, notifying of both action and dismiss' ,
284
280
fakeAsync ( ( ) => {
285
- let dismissObservableCompleted = false ;
286
- let actionObservableCompleted = false ;
287
- let snackBarRef = snackBar . open ( 'Some content' , 'Dismiss' ) ;
288
- viewContainerFixture . detectChanges ( ) ;
289
-
290
- snackBarRef . afterDismissed ( ) . subscribe ( undefined , undefined , ( ) => {
291
- dismissObservableCompleted = true ;
292
- } ) ;
293
- snackBarRef . onAction ( ) . subscribe ( undefined , undefined , ( ) => {
294
- actionObservableCompleted = true ;
295
- } ) ;
281
+ const dismissCompleteSpy = jasmine . createSpy ( 'dismiss complete spy' ) ;
282
+ const actionCompleteSpy = jasmine . createSpy ( 'action complete spy' ) ;
283
+ const snackBarRef = snackBar . open ( 'Some content' , 'Dismiss' ) ;
284
+ viewContainerFixture . detectChanges ( ) ;
285
+
286
+ snackBarRef . afterDismissed ( ) . subscribe ( undefined , undefined , dismissCompleteSpy ) ;
287
+ snackBarRef . onAction ( ) . subscribe ( undefined , undefined , actionCompleteSpy ) ;
296
288
297
- let actionButton =
289
+ const actionButton =
298
290
overlayContainerElement . querySelector ( '.mat-simple-snackbar-action' ) as HTMLButtonElement ;
299
291
actionButton . click ( ) ;
300
292
viewContainerFixture . detectChanges ( ) ;
301
293
tick ( ) ;
302
294
303
- expect ( dismissObservableCompleted ) . toBeTruthy ( 'Expected the snack bar to be dismissed' ) ;
304
- expect ( actionObservableCompleted ) . toBeTruthy ( 'Expected the snack bar to notify of action' ) ;
295
+ expect ( dismissCompleteSpy ) . toHaveBeenCalled ( ) ;
296
+ expect ( actionCompleteSpy ) . toHaveBeenCalled ( ) ;
305
297
306
298
tick ( 500 ) ;
307
299
} ) ) ;
308
300
309
301
it ( 'should allow manually closing with an action' , fakeAsync ( ( ) => {
310
- let dismissObservableCompleted = false ;
311
- let actionObservableCompleted = false ;
312
- let snackBarRef = snackBar . open ( 'Some content' ) ;
302
+ const dismissCompleteSpy = jasmine . createSpy ( 'dismiss complete spy' ) ;
303
+ const actionCompleteSpy = jasmine . createSpy ( 'action complete spy' ) ;
304
+ const snackBarRef = snackBar . open ( 'Some content' ) ;
313
305
viewContainerFixture . detectChanges ( ) ;
314
306
315
- snackBarRef . afterDismissed ( ) . subscribe ( undefined , undefined , ( ) => {
316
- dismissObservableCompleted = true ;
317
- } ) ;
318
- snackBarRef . onAction ( ) . subscribe ( undefined , undefined , ( ) => {
319
- actionObservableCompleted = true ;
320
- } ) ;
307
+ snackBarRef . afterDismissed ( ) . subscribe ( undefined , undefined , dismissCompleteSpy ) ;
308
+ snackBarRef . onAction ( ) . subscribe ( undefined , undefined , actionCompleteSpy ) ;
321
309
322
310
snackBarRef . closeWithAction ( ) ;
323
311
viewContainerFixture . detectChanges ( ) ;
324
312
tick ( ) ;
325
313
326
- expect ( dismissObservableCompleted ) . toBeTruthy ( 'Expected the snack bar to be dismissed' ) ;
327
- expect ( actionObservableCompleted ) . toBeTruthy ( 'Expected the snack bar to notify of action' ) ;
314
+ expect ( dismissCompleteSpy ) . toHaveBeenCalled ( ) ;
315
+ expect ( actionCompleteSpy ) . toHaveBeenCalled ( ) ;
316
+
317
+ tick ( 500 ) ;
318
+ } ) ) ;
319
+
320
+ it ( 'should complete the onAction stream when not closing via an action' , fakeAsync ( ( ) => {
321
+ const actionCompleteSpy = jasmine . createSpy ( 'action complete spy' ) ;
322
+ const snackBarRef = snackBar . open ( 'Some content' ) ;
323
+ viewContainerFixture . detectChanges ( ) ;
324
+
325
+ snackBarRef . onAction ( ) . subscribe ( undefined , undefined , actionCompleteSpy ) ;
326
+ snackBarRef . dismiss ( ) ;
327
+ viewContainerFixture . detectChanges ( ) ;
328
+ tick ( ) ;
329
+
330
+ expect ( actionCompleteSpy ) . toHaveBeenCalled ( ) ;
328
331
329
332
tick ( 500 ) ;
330
333
} ) ) ;
331
334
332
335
it ( 'should dismiss automatically after a specified timeout' , fakeAsync ( ( ) => {
333
- let dismissObservableCompleted = false ;
334
336
let config = new MatSnackBarConfig ( ) ;
335
337
config . duration = 250 ;
336
338
let snackBarRef = snackBar . open ( 'content' , 'test' , config ) ;
337
- snackBarRef . afterDismissed ( ) . subscribe ( ( ) => {
338
- dismissObservableCompleted = true ;
339
- } ) ;
339
+ let afterDismissSpy = jasmine . createSpy ( 'after dismiss spy' ) ;
340
+ snackBarRef . afterDismissed ( ) . subscribe ( afterDismissSpy ) ;
340
341
341
342
viewContainerFixture . detectChanges ( ) ;
342
343
tick ( ) ;
343
- expect ( dismissObservableCompleted ) . toBeFalsy ( 'Expected the snack bar not to be dismissed' ) ;
344
+ expect ( afterDismissSpy ) . not . toHaveBeenCalled ( ) ;
344
345
345
346
tick ( 1000 ) ;
346
347
viewContainerFixture . detectChanges ( ) ;
347
348
tick ( ) ;
348
- expect ( dismissObservableCompleted ) . toBeTruthy ( 'Expected the snack bar to be dismissed' ) ;
349
+ expect ( afterDismissSpy ) . toHaveBeenCalled ( ) ;
349
350
} ) ) ;
350
351
351
352
it ( 'should clear the dismiss timeout when dismissed before timeout expiration' , fakeAsync ( ( ) => {
@@ -411,24 +412,20 @@ describe('MatSnackBar', () => {
411
412
} ) ;
412
413
413
414
it ( 'should allow manually closing with an action' , fakeAsync ( ( ) => {
414
- let dismissObservableCompleted = false ;
415
- let actionObservableCompleted = false ;
415
+ const dismissCompleteSpy = jasmine . createSpy ( 'dismiss complete spy' ) ;
416
+ const actionCompleteSpy = jasmine . createSpy ( 'action complete spy' ) ;
416
417
const snackBarRef = snackBar . openFromComponent ( BurritosNotification ) ;
417
418
viewContainerFixture . detectChanges ( ) ;
418
419
419
- snackBarRef . afterDismissed ( ) . subscribe ( undefined , undefined , ( ) => {
420
- dismissObservableCompleted = true ;
421
- } ) ;
422
- snackBarRef . onAction ( ) . subscribe ( undefined , undefined , ( ) => {
423
- actionObservableCompleted = true ;
424
- } ) ;
420
+ snackBarRef . afterDismissed ( ) . subscribe ( undefined , undefined , dismissCompleteSpy ) ;
421
+ snackBarRef . onAction ( ) . subscribe ( undefined , undefined , actionCompleteSpy ) ;
425
422
426
423
snackBarRef . closeWithAction ( ) ;
427
424
viewContainerFixture . detectChanges ( ) ;
428
425
tick ( ) ;
429
426
430
- expect ( dismissObservableCompleted ) . toBeTruthy ( 'Expected the snack bar to be dismissed' ) ;
431
- expect ( actionObservableCompleted ) . toBeTruthy ( 'Expected the snack bar to notify of action' ) ;
427
+ expect ( dismissCompleteSpy ) . toHaveBeenCalled ( ) ;
428
+ expect ( actionCompleteSpy ) . toHaveBeenCalled ( ) ;
432
429
433
430
tick ( 500 ) ;
434
431
} ) ) ;
0 commit comments