@@ -152,21 +152,22 @@ describe('MdRadio', () => {
152
152
expect ( spies [ 1 ] ) . toHaveBeenCalledTimes ( 1 ) ;
153
153
} ) ;
154
154
155
- it ( 'should emit a change event from the radio group' , ( ) => {
155
+ it ( `should not emit a change event from the radio group when change group value
156
+ programmatically` , ( ) => {
156
157
expect ( groupInstance . value ) . toBeFalsy ( ) ;
157
158
158
159
let changeSpy = jasmine . createSpy ( 'radio-group change listener' ) ;
159
160
groupInstance . change . subscribe ( changeSpy ) ;
160
161
161
- groupInstance . value = 'fire' ;
162
+ radioLabelElements [ 0 ] . click ( ) ;
162
163
fixture . detectChanges ( ) ;
163
164
164
- expect ( changeSpy ) . toHaveBeenCalled ( ) ;
165
+ expect ( changeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
165
166
166
167
groupInstance . value = 'water' ;
167
168
fixture . detectChanges ( ) ;
168
169
169
- expect ( changeSpy ) . toHaveBeenCalledTimes ( 2 ) ;
170
+ expect ( changeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
170
171
} ) ;
171
172
172
173
// TODO(jelbourn): test this in an e2e test with *real* focus, rather than faking
@@ -234,42 +235,44 @@ describe('MdRadio', () => {
234
235
}
235
236
} ) ) ;
236
237
237
- it ( ' should update the group\ 's selected radio to null when unchecking that radio '
238
- + ' programmatically' , ( ) => {
238
+ it ( ` should update the group's selected radio to null when unchecking that radio
239
+ programmatically` , ( ) => {
239
240
let changeSpy = jasmine . createSpy ( 'radio-group change listener' ) ;
240
241
groupInstance . change . subscribe ( changeSpy ) ;
241
242
radioInstances [ 0 ] . checked = true ;
242
243
243
244
fixture . detectChanges ( ) ;
244
245
245
- expect ( changeSpy ) . toHaveBeenCalled ( ) ;
246
+ expect ( changeSpy ) . not . toHaveBeenCalled ( ) ;
246
247
expect ( groupInstance . value ) . toBeTruthy ( ) ;
247
248
248
249
radioInstances [ 0 ] . checked = false ;
249
250
250
251
fixture . detectChanges ( ) ;
251
252
252
- expect ( changeSpy ) . toHaveBeenCalledTimes ( 2 ) ;
253
+ expect ( changeSpy ) . not . toHaveBeenCalled ( ) ;
253
254
expect ( groupInstance . value ) . toBeFalsy ( ) ;
254
255
expect ( radioInstances . every ( radio => ! radio . checked ) ) . toBe ( true ) ;
255
256
expect ( groupInstance . selected ) . toBeNull ( ) ;
256
257
} ) ;
257
258
258
- it ( 'should fire a change event from the group whenever a radio checked state changes' , ( ) => {
259
+ it ( 'should not fire a change event from the group when a radio checked state changes' , ( ) => {
259
260
let changeSpy = jasmine . createSpy ( 'radio-group change listener' ) ;
260
261
groupInstance . change . subscribe ( changeSpy ) ;
261
262
radioInstances [ 0 ] . checked = true ;
262
263
263
264
fixture . detectChanges ( ) ;
264
265
265
- expect ( changeSpy ) . toHaveBeenCalled ( ) ;
266
+ expect ( changeSpy ) . not . toHaveBeenCalled ( ) ;
266
267
expect ( groupInstance . value ) . toBeTruthy ( ) ;
268
+ expect ( groupInstance . value ) . toBe ( 'fire' ) ;
267
269
268
270
radioInstances [ 1 ] . checked = true ;
269
271
270
272
fixture . detectChanges ( ) ;
271
273
272
- expect ( changeSpy ) . toHaveBeenCalledTimes ( 2 ) ;
274
+ expect ( groupInstance . value ) . toBe ( 'water' ) ;
275
+ expect ( changeSpy ) . not . toHaveBeenCalled ( ) ;
273
276
} ) ;
274
277
} ) ;
275
278
0 commit comments