@@ -102,7 +102,7 @@ describe('MdCheckbox', () => {
102
102
expect ( inputElement . indeterminate ) . toBe ( false ) ;
103
103
} ) ;
104
104
105
- it ( 'should set indeterminate to false when input clicked' , async ( ( ) => {
105
+ it ( 'should set indeterminate to false when input clicked' , fakeAsync ( ( ) => {
106
106
testComponent . isIndeterminate = true ;
107
107
fixture . detectChanges ( ) ;
108
108
@@ -113,33 +113,40 @@ describe('MdCheckbox', () => {
113
113
inputElement . click ( ) ;
114
114
fixture . detectChanges ( ) ;
115
115
116
- fixture . whenStable ( ) . then ( ( ) => {
117
- fixture . detectChanges ( ) ;
118
- expect ( checkboxInstance . checked ) . toBe ( true ) ;
119
- expect ( inputElement . indeterminate ) . toBe ( false ) ;
120
- expect ( inputElement . checked ) . toBe ( true ) ;
121
- expect ( testComponent . isIndeterminate ) . toBe ( false ) ;
116
+ // Flush the microtasks because the forms module updates the model state asynchronously.
117
+ flushMicrotasks ( ) ;
122
118
123
- testComponent . isIndeterminate = true ;
124
- fixture . detectChanges ( ) ;
119
+ // The checked property has been updated from the model and now the view needs
120
+ // to reflect the state change.
121
+ fixture . detectChanges ( ) ;
125
122
126
- expect ( checkboxInstance . indeterminate ) . toBe ( true ) ;
127
- expect ( inputElement . indeterminate ) . toBe ( true ) ;
128
- expect ( inputElement . checked ) . toBe ( true ) ;
129
- expect ( testComponent . isIndeterminate ) . toBe ( true ) ;
123
+ expect ( checkboxInstance . checked ) . toBe ( true ) ;
124
+ expect ( inputElement . indeterminate ) . toBe ( false ) ;
125
+ expect ( inputElement . checked ) . toBe ( true ) ;
126
+ expect ( testComponent . isIndeterminate ) . toBe ( false ) ;
130
127
131
- inputElement . click ( ) ;
132
- fixture . detectChanges ( ) ;
128
+ testComponent . isIndeterminate = true ;
129
+ fixture . detectChanges ( ) ;
133
130
134
- fixture . whenStable ( ) . then ( ( ) => {
135
- fixture . detectChanges ( ) ;
136
- expect ( checkboxInstance . checked ) . toBe ( false ) ;
137
- expect ( inputElement . indeterminate ) . toBe ( false ) ;
138
- expect ( inputElement . checked ) . toBe ( false ) ;
139
- expect ( testComponent . isIndeterminate ) . toBe ( false ) ;
140
- } ) ;
141
- } ) ;
131
+ expect ( checkboxInstance . indeterminate ) . toBe ( true ) ;
132
+ expect ( inputElement . indeterminate ) . toBe ( true ) ;
133
+ expect ( inputElement . checked ) . toBe ( true ) ;
134
+ expect ( testComponent . isIndeterminate ) . toBe ( true ) ;
135
+
136
+ inputElement . click ( ) ;
137
+ fixture . detectChanges ( ) ;
142
138
139
+ // Flush the microtasks because the forms module updates the model state asynchronously.
140
+ flushMicrotasks ( ) ;
141
+
142
+ // The checked property has been updated from the model and now the view needs
143
+ // to reflect the state change.
144
+ fixture . detectChanges ( ) ;
145
+
146
+ expect ( checkboxInstance . checked ) . toBe ( false ) ;
147
+ expect ( inputElement . indeterminate ) . toBe ( false ) ;
148
+ expect ( inputElement . checked ) . toBe ( false ) ;
149
+ expect ( testComponent . isIndeterminate ) . toBe ( false ) ;
143
150
} ) ) ;
144
151
145
152
it ( 'should not set indeterminate to false when checked is set programmatically' , async ( ( ) => {
@@ -190,7 +197,7 @@ describe('MdCheckbox', () => {
190
197
expect ( checkboxInstance . checked ) . toBe ( false ) ;
191
198
} ) ;
192
199
193
- it ( 'should change from indeterminate to checked on click' , async ( ( ) => {
200
+ it ( 'should change from indeterminate to checked on click' , fakeAsync ( ( ) => {
194
201
testComponent . isChecked = false ;
195
202
testComponent . isIndeterminate = true ;
196
203
fixture . detectChanges ( ) ;
@@ -200,16 +207,17 @@ describe('MdCheckbox', () => {
200
207
201
208
checkboxInstance . _onInputClick ( < Event > { stopPropagation : ( ) => { } } ) ;
202
209
203
- fixture . whenStable ( ) . then ( ( ) => {
204
- expect ( checkboxInstance . checked ) . toBe ( true ) ;
205
- expect ( checkboxInstance . indeterminate ) . toBe ( false ) ;
210
+ // Flush the microtasks because the indeterminate state will be updated in the next tick.
211
+ flushMicrotasks ( ) ;
206
212
207
- checkboxInstance . _onInputClick ( < Event > { stopPropagation : ( ) => { } } ) ;
208
- fixture . detectChanges ( ) ;
213
+ expect ( checkboxInstance . checked ) . toBe ( true ) ;
214
+ expect ( checkboxInstance . indeterminate ) . toBe ( false ) ;
209
215
210
- expect ( checkboxInstance . checked ) . toBe ( false ) ;
211
- expect ( checkboxInstance . indeterminate ) . toBe ( false ) ;
212
- } ) ;
216
+ checkboxInstance . _onInputClick ( < Event > { stopPropagation : ( ) => { } } ) ;
217
+ fixture . detectChanges ( ) ;
218
+
219
+ expect ( checkboxInstance . checked ) . toBe ( false ) ;
220
+ expect ( checkboxInstance . indeterminate ) . toBe ( false ) ;
213
221
} ) ) ;
214
222
215
223
it ( 'should add and remove disabled state' , ( ) => {
@@ -242,17 +250,18 @@ describe('MdCheckbox', () => {
242
250
expect ( checkboxInstance . checked ) . toBe ( false ) ;
243
251
} ) ;
244
252
245
- it ( 'should overwrite indeterminate state when clicked' , async ( ( ) => {
253
+ it ( 'should overwrite indeterminate state when clicked' , fakeAsync ( ( ) => {
246
254
testComponent . isIndeterminate = true ;
247
255
fixture . detectChanges ( ) ;
248
256
249
257
inputElement . click ( ) ;
250
258
fixture . detectChanges ( ) ;
251
259
252
- fixture . whenStable ( ) . then ( ( ) => {
253
- expect ( checkboxInstance . checked ) . toBe ( true ) ;
254
- expect ( checkboxInstance . indeterminate ) . toBe ( false ) ;
255
- } ) ;
260
+ // Flush the microtasks because the indeterminate state will be updated in the next tick.
261
+ flushMicrotasks ( ) ;
262
+
263
+ expect ( checkboxInstance . checked ) . toBe ( true ) ;
264
+ expect ( checkboxInstance . indeterminate ) . toBe ( false ) ;
256
265
} ) ) ;
257
266
258
267
it ( 'should preserve the user-provided id' , ( ) => {
0 commit comments