1
1
import {
2
- inject ,
3
- async ,
4
- ComponentFixture ,
5
- TestBed
2
+ inject ,
3
+ async ,
4
+ ComponentFixture ,
5
+ TestBed ,
6
6
} from '@angular/core/testing' ;
7
7
import {
8
8
NgModule ,
@@ -91,7 +91,7 @@ describe('MdSnackBar', () => {
91
91
. toBe ( 'BUTTON' , 'Expected snack bar action label to be a <button>' ) ;
92
92
expect ( buttonElement . textContent )
93
93
. toBe ( simpleActionLabel ,
94
- `Expected the snack bar action labe; to be '${ simpleActionLabel } '` ) ;
94
+ `Expected the snack bar action label to be '${ simpleActionLabel } '` ) ;
95
95
} ) ;
96
96
97
97
it ( 'should open a simple message with no button' , ( ) => {
@@ -114,25 +114,28 @@ describe('MdSnackBar', () => {
114
114
. toBeNull ( 'Expected the query selection for action label to be null' ) ;
115
115
} ) ;
116
116
117
- it ( 'should dismiss the snack bar and remove itself from the view' , ( ) => {
117
+ it ( 'should dismiss the snack bar and remove itself from the view' , async ( ( ) => {
118
118
let config = new MdSnackBarConfig ( testViewContainerRef ) ;
119
- let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
120
- let dismissed = true ;
121
- snackBarRef . afterDismissed ( ) . subscribe ( result => {
122
- dismissed = true ;
123
- } ) ;
119
+ let dismissObservableCompleted = false ;
124
120
121
+ let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
125
122
viewContainerFixture . detectChanges ( ) ;
126
123
expect ( overlayContainerElement . childElementCount )
127
124
. toBeGreaterThan ( 0 , 'Expected overlay container element to have at least one child' ) ;
128
125
129
- snackBarRef . dismiss ( ) ;
130
126
snackBarRef . afterDismissed ( ) . subscribe ( null , null , ( ) => {
131
- expect ( dismissed ) . toBeTruthy ( 'Expected the snack bar to be dismissed' ) ;
127
+ dismissObservableCompleted = true ;
128
+ } ) ;
129
+
130
+ snackBarRef . dismiss ( ) ;
131
+ viewContainerFixture . detectChanges ( ) ; // Run through animations for dismissal
132
+
133
+ viewContainerFixture . whenStable ( ) . then ( ( ) => {
134
+ expect ( dismissObservableCompleted ) . toBeTruthy ( 'Expected the snack bar to be dismissed' ) ;
132
135
expect ( overlayContainerElement . childElementCount )
133
136
. toBe ( 0 , 'Expected the overlay container element to have no child elements' ) ;
134
137
} ) ;
135
- } ) ;
138
+ } ) ) ;
136
139
137
140
it ( 'should open a custom component' , ( ) => {
138
141
let config = new MdSnackBarConfig ( testViewContainerRef ) ;
@@ -166,9 +169,10 @@ describe('MdSnackBar', () => {
166
169
} ) ;
167
170
168
171
it ( `should set the old snack bar animation state to complete and the new snack bar animation
169
- state to visible on entry of new snack bar` , ( ) => {
172
+ state to visible on entry of new snack bar` , async ( ( ) => {
170
173
let config = new MdSnackBarConfig ( testViewContainerRef ) ;
171
174
let snackBarRef = snackBar . open ( simpleMessage , null , config ) ;
175
+ let dismissObservableCompleted = false ;
172
176
173
177
viewContainerFixture . detectChanges ( ) ;
174
178
expect ( snackBarRef . containerInstance . animationState )
@@ -179,12 +183,17 @@ describe('MdSnackBar', () => {
179
183
180
184
viewContainerFixture . detectChanges ( ) ;
181
185
snackBarRef . afterDismissed ( ) . subscribe ( null , null , ( ) => {
186
+ dismissObservableCompleted = true ;
187
+ } ) ;
188
+
189
+ viewContainerFixture . whenStable ( ) . then ( ( ) => {
190
+ expect ( dismissObservableCompleted ) . toBe ( true ) ;
182
191
expect ( snackBarRef . containerInstance . animationState )
183
192
. toBe ( 'complete' , `Expected the animation state would be 'complete'.` ) ;
184
193
expect ( snackBarRef2 . containerInstance . animationState )
185
194
. toBe ( 'visible' , `Expected the animation state would be 'visible'.` ) ;
186
195
} ) ;
187
- } ) ;
196
+ } ) ) ;
188
197
} ) ;
189
198
190
199
@Directive ( { selector : 'dir-with-view-container' } )
0 commit comments