@@ -58,15 +58,18 @@ describe('MdSlideToggle', () => {
58
58
} ) ;
59
59
} ) ) ;
60
60
61
-
62
- it ( 'should update the model correctly' , ( ) => {
61
+ // TODO(kara); update when core/testing adds fix
62
+ it ( 'should update the model correctly' , async ( ( ) => {
63
63
expect ( slideToggleElement . classList ) . not . toContain ( 'md-checked' ) ;
64
64
65
65
testComponent . slideModel = true ;
66
66
fixture . detectChanges ( ) ;
67
+ fixture . whenStable ( ) . then ( ( ) => {
68
+ fixture . detectChanges ( ) ;
69
+ expect ( slideToggleElement . classList ) . toContain ( 'md-checked' ) ;
70
+ } ) ;
67
71
68
- expect ( slideToggleElement . classList ) . toContain ( 'md-checked' ) ;
69
- } ) ;
72
+ } ) ) ;
70
73
71
74
it ( 'should apply class based on color attribute' , ( ) => {
72
75
testComponent . slideColor = 'primary' ;
@@ -127,11 +130,11 @@ describe('MdSlideToggle', () => {
127
130
expect ( testComponent . onSlideClick ) . toHaveBeenCalledTimes ( 1 ) ;
128
131
} ) ;
129
132
130
- it ( 'should trigger the change event properly' , async ( ( ) => {
133
+ it ( 'should trigger the change event properly' , async ( ( ) => {
131
134
expect ( inputElement . checked ) . toBe ( false ) ;
132
135
expect ( slideToggleElement . classList ) . not . toContain ( 'md-checked' ) ;
133
136
134
- labelElement . click ( ) ;
137
+ labelElement . click ( ) ;
135
138
fixture . detectChanges ( ) ;
136
139
137
140
expect ( inputElement . checked ) . toBe ( true ) ;
@@ -140,33 +143,33 @@ describe('MdSlideToggle', () => {
140
143
// Wait for the fixture to become stable, because the EventEmitter for the change event,
141
144
// will only fire after the zone async change detection has finished.
142
145
fixture . whenStable ( ) . then ( ( ) => {
143
- // The change event shouldn't fire, because the value change was not caused
144
- // by any interaction.
146
+ // The change event shouldn't fire, because the value change was not caused
147
+ // by any interaction.
145
148
expect ( testComponent . onSlideChange ) . toHaveBeenCalledTimes ( 1 ) ;
146
149
} ) ;
147
150
148
151
} ) ) ;
149
152
150
- it ( 'should not trigger the change event by changing the native value' , async ( ( ) => {
151
- expect ( inputElement . checked ) . toBe ( false ) ;
152
- expect ( slideToggleElement . classList ) . not . toContain ( 'md-checked' ) ;
153
-
154
- testComponent . slideChecked = true ;
155
- fixture . detectChanges ( ) ;
156
-
157
- expect ( inputElement . checked ) . toBe ( true ) ;
158
- expect ( slideToggleElement . classList ) . toContain ( 'md-checked' ) ;
159
-
160
- // Wait for the fixture to become stable, because the EventEmitter for the change event,
161
- // will only fire after the zone async change detection has finished.
162
- fixture . whenStable ( ) . then ( ( ) => {
163
- // The change event shouldn't fire, because the value change was not caused
164
- // by any interaction.
165
- expect ( testComponent . onSlideChange ) . not . toHaveBeenCalled ( ) ;
166
- } ) ;
167
-
168
- } ) ) ;
169
-
153
+ it ( 'should not trigger the change event by changing the native value' , async ( ( ) => {
154
+ expect ( inputElement . checked ) . toBe ( false ) ;
155
+ expect ( slideToggleElement . classList ) . not . toContain ( 'md-checked' ) ;
156
+
157
+ testComponent . slideChecked = true ;
158
+ fixture . detectChanges ( ) ;
159
+
160
+ expect ( inputElement . checked ) . toBe ( true ) ;
161
+ expect ( slideToggleElement . classList ) . toContain ( 'md-checked' ) ;
162
+
163
+ // Wait for the fixture to become stable, because the EventEmitter for the change event,
164
+ // will only fire after the zone async change detection has finished.
165
+ fixture . whenStable ( ) . then ( ( ) => {
166
+ // The change event shouldn't fire, because the value change was not caused
167
+ // by any interaction.
168
+ expect ( testComponent . onSlideChange ) . not . toHaveBeenCalled ( ) ;
169
+ } ) ;
170
+
171
+ } ) ) ;
172
+
170
173
it ( 'should not trigger the change event on initialization' , async ( ( ) => {
171
174
expect ( inputElement . checked ) . toBe ( false ) ;
172
175
expect ( slideToggleElement . classList ) . not . toContain ( 'md-checked' ) ;
@@ -180,8 +183,8 @@ describe('MdSlideToggle', () => {
180
183
// Wait for the fixture to become stable, because the EventEmitter for the change event,
181
184
// will only fire after the zone async change detection has finished.
182
185
fixture . whenStable ( ) . then ( ( ) => {
183
- // The change event shouldn't fire, because the native input element is not focused.
184
- expect ( testComponent . onSlideChange ) . not . toHaveBeenCalled ( ) ;
186
+ // The change event shouldn't fire, because the native input element is not focused.
187
+ expect ( testComponent . onSlideChange ) . not . toHaveBeenCalled ( ) ;
185
188
} ) ;
186
189
187
190
} ) ) ;
@@ -315,17 +318,20 @@ describe('MdSlideToggle', () => {
315
318
expect ( slideToggleElement . classList ) . not . toContain ( 'md-checked' ) ;
316
319
} ) ;
317
320
318
- it ( 'should not set the control to touched when changing the model' , ( ) => {
321
+ // TODO(kara): update when core/testing adds fix
322
+ it ( 'should not set the control to touched when changing the model' , async ( ( ) => {
319
323
// The control should start off with being untouched.
320
324
expect ( slideToggleControl . touched ) . toBe ( false ) ;
321
325
322
326
testComponent . slideModel = true ;
323
327
fixture . detectChanges ( ) ;
324
-
325
- expect ( slideToggleControl . touched ) . toBe ( false ) ;
326
- expect ( slideToggle . checked ) . toBe ( true ) ;
327
- expect ( slideToggleElement . classList ) . toContain ( 'md-checked' ) ;
328
- } ) ;
328
+ fixture . whenStable ( ) . then ( ( ) => {
329
+ fixture . detectChanges ( ) ;
330
+ expect ( slideToggleControl . touched ) . toBe ( false ) ;
331
+ expect ( slideToggle . checked ) . toBe ( true ) ;
332
+ expect ( slideToggleElement . classList ) . toContain ( 'md-checked' ) ;
333
+ } ) ;
334
+ } ) ) ;
329
335
330
336
it ( 'should correctly set the slide-toggle to checked on focus' , ( ) => {
331
337
expect ( slideToggleElement . classList ) . not . toContain ( 'md-slide-toggle-focused' ) ;
0 commit comments