@@ -58,15 +58,18 @@ describe('MdSlideToggle', () => {
5858 } ) ;
5959 } ) ) ;
6060
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 ( ( ) => {
6363 expect ( slideToggleElement . classList ) . not . toContain ( 'md-checked' ) ;
6464
6565 testComponent . slideModel = true ;
6666 fixture . detectChanges ( ) ;
67+ fixture . whenStable ( ) . then ( ( ) => {
68+ fixture . detectChanges ( ) ;
69+ expect ( slideToggleElement . classList ) . toContain ( 'md-checked' ) ;
70+ } ) ;
6771
68- expect ( slideToggleElement . classList ) . toContain ( 'md-checked' ) ;
69- } ) ;
72+ } ) ) ;
7073
7174 it ( 'should apply class based on color attribute' , ( ) => {
7275 testComponent . slideColor = 'primary' ;
@@ -127,11 +130,11 @@ describe('MdSlideToggle', () => {
127130 expect ( testComponent . onSlideClick ) . toHaveBeenCalledTimes ( 1 ) ;
128131 } ) ;
129132
130- it ( 'should trigger the change event properly' , async ( ( ) => {
133+ it ( 'should trigger the change event properly' , async ( ( ) => {
131134 expect ( inputElement . checked ) . toBe ( false ) ;
132135 expect ( slideToggleElement . classList ) . not . toContain ( 'md-checked' ) ;
133136
134- labelElement . click ( ) ;
137+ labelElement . click ( ) ;
135138 fixture . detectChanges ( ) ;
136139
137140 expect ( inputElement . checked ) . toBe ( true ) ;
@@ -140,33 +143,33 @@ describe('MdSlideToggle', () => {
140143 // Wait for the fixture to become stable, because the EventEmitter for the change event,
141144 // will only fire after the zone async change detection has finished.
142145 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.
145148 expect ( testComponent . onSlideChange ) . toHaveBeenCalledTimes ( 1 ) ;
146149 } ) ;
147150
148151 } ) ) ;
149152
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+
170173 it ( 'should not trigger the change event on initialization' , async ( ( ) => {
171174 expect ( inputElement . checked ) . toBe ( false ) ;
172175 expect ( slideToggleElement . classList ) . not . toContain ( 'md-checked' ) ;
@@ -180,8 +183,8 @@ describe('MdSlideToggle', () => {
180183 // Wait for the fixture to become stable, because the EventEmitter for the change event,
181184 // will only fire after the zone async change detection has finished.
182185 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 ( ) ;
185188 } ) ;
186189
187190 } ) ) ;
@@ -315,17 +318,20 @@ describe('MdSlideToggle', () => {
315318 expect ( slideToggleElement . classList ) . not . toContain ( 'md-checked' ) ;
316319 } ) ;
317320
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 ( ( ) => {
319323 // The control should start off with being untouched.
320324 expect ( slideToggleControl . touched ) . toBe ( false ) ;
321325
322326 testComponent . slideModel = true ;
323327 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+ } ) ) ;
329335
330336 it ( 'should correctly set the slide-toggle to checked on focus' , ( ) => {
331337 expect ( slideToggleElement . classList ) . not . toContain ( 'md-slide-toggle-focused' ) ;
0 commit comments