@@ -407,14 +407,40 @@ describe('MdSlideToggle', () => {
407407 } ) ;
408408
409409 describe ( 'custom template' , ( ) => {
410+
410411 it ( 'should not trigger the change event on initialization' , async ( ( ) => {
411- let fixture = TestBed . createComponent ( SlideToggleTestApp ) ;
412+ const fixture = TestBed . createComponent ( SlideToggleTestApp ) ;
412413 fixture . componentInstance . slideModel = true ;
413414 fixture . componentInstance . slideChecked = true ;
414415 fixture . detectChanges ( ) ;
415416
416417 expect ( fixture . componentInstance . lastEvent ) . toBeFalsy ( ) ;
417418 } ) ) ;
419+
420+ it ( 'should update checked state on click if control is checked initially' , async ( ( ) => {
421+ const fixture = TestBed . createComponent ( SlideToggleTestApp ) ;
422+ const slideToggleInstance = fixture . debugElement
423+ . query ( By . directive ( MdSlideToggle ) ) . componentInstance ;
424+ const labelElement = fixture . debugElement . query ( By . css ( 'label' ) ) . nativeElement ;
425+
426+ fixture . componentInstance . slideModel = true ;
427+ fixture . detectChanges ( ) ;
428+
429+ fixture . whenStable ( ) . then ( ( ) => {
430+ // Now the new checked variable has been updated in the slide-toggle and the slide-toggle
431+ // is marked for check because it still needs to update the underlying input.
432+ fixture . detectChanges ( ) ;
433+
434+ expect ( slideToggleInstance . checked )
435+ . toBe ( true , 'Expected slide-toggle to be checked initially' ) ;
436+
437+ labelElement . click ( ) ;
438+ fixture . detectChanges ( ) ;
439+
440+ expect ( slideToggleInstance . checked )
441+ . toBe ( false , 'Expected slide-toggle to be no longer checked after label click.' ) ;
442+ } ) ;
443+ } ) ) ;
418444 } ) ;
419445
420446 describe ( 'with forms' , ( ) => {
0 commit comments