@@ -129,11 +129,11 @@ describe('MdSlideToggle', () => {
129129 expect ( testComponent . onSlideClick ) . toHaveBeenCalledTimes ( 1 ) ;
130130 } ) ;
131131
132- it ( 'should not trigger the change event multiple times ' , async ( ( ) => {
132+ it ( 'should trigger the change event properly ' , async ( ( ) => {
133133 expect ( inputElement . checked ) . toBe ( false ) ;
134134 expect ( slideToggleElement . classList ) . not . toContain ( 'md-checked' ) ;
135135
136- testComponent . slideChecked = true ;
136+ labelElement . click ( ) ;
137137 fixture . detectChanges ( ) ;
138138
139139 expect ( inputElement . checked ) . toBe ( true ) ;
@@ -142,11 +142,33 @@ describe('MdSlideToggle', () => {
142142 // Wait for the fixture to become stable, because the EventEmitter for the change event,
143143 // will only fire after the zone async change detection has finished.
144144 fixture . whenStable ( ) . then ( ( ) => {
145+ // The change event shouldn't fire, because the value change was not caused
146+ // by any interaction.
145147 expect ( testComponent . onSlideChange ) . toHaveBeenCalledTimes ( 1 ) ;
146148 } ) ;
147149
148150 } ) ) ;
149151
152+ it ( 'should not trigger the change event by changing the native value' , async ( ( ) => {
153+ expect ( inputElement . checked ) . toBe ( false ) ;
154+ expect ( slideToggleElement . classList ) . not . toContain ( 'md-checked' ) ;
155+
156+ testComponent . slideChecked = true ;
157+ fixture . detectChanges ( ) ;
158+
159+ expect ( inputElement . checked ) . toBe ( true ) ;
160+ expect ( slideToggleElement . classList ) . toContain ( 'md-checked' ) ;
161+
162+ // Wait for the fixture to become stable, because the EventEmitter for the change event,
163+ // will only fire after the zone async change detection has finished.
164+ fixture . whenStable ( ) . then ( ( ) => {
165+ // The change event shouldn't fire, because the value change was not caused
166+ // by any interaction.
167+ expect ( testComponent . onSlideChange ) . not . toHaveBeenCalled ( ) ;
168+ } ) ;
169+
170+ } ) ) ;
171+
150172 it ( 'should not trigger the change event on initialization' , async ( ( ) => {
151173 expect ( inputElement . checked ) . toBe ( false ) ;
152174 expect ( slideToggleElement . classList ) . not . toContain ( 'md-checked' ) ;
@@ -160,7 +182,8 @@ describe('MdSlideToggle', () => {
160182 // Wait for the fixture to become stable, because the EventEmitter for the change event,
161183 // will only fire after the zone async change detection has finished.
162184 fixture . whenStable ( ) . then ( ( ) => {
163- expect ( testComponent . onSlideChange ) . toHaveBeenCalledTimes ( 1 ) ;
185+ // The change event shouldn't fire, because the native input element is not focused.
186+ expect ( testComponent . onSlideChange ) . not . toHaveBeenCalled ( ) ;
164187 } ) ;
165188
166189 } ) ) ;
0 commit comments