@@ -297,6 +297,50 @@ describe('MdRadio', () => {
297
297
} ) ) ;
298
298
} ) ;
299
299
300
+ describe ( 'group with ngModel and change event' , ( ) => {
301
+ let fixture : ComponentFixture < RadioGroupWithNgModel > ;
302
+ let groupDebugElement : DebugElement ;
303
+ let groupNativeElement : HTMLElement ;
304
+ let radioDebugElements : DebugElement [ ] ;
305
+ let radioNativeElements : HTMLElement [ ] ;
306
+ let groupInstance : MdRadioGroup ;
307
+ let radioInstances : MdRadioButton [ ] ;
308
+ let testComponent : RadioGroupWithNgModel ;
309
+ let groupNgControl : NgControl ;
310
+
311
+ beforeEach ( async ( ( ) => {
312
+ builder . createAsync ( RadioGroupWithNgModel ) . then ( f => {
313
+ fixture = f ;
314
+
315
+ testComponent = fixture . componentInstance ;
316
+
317
+ groupDebugElement = fixture . debugElement . query ( By . directive ( MdRadioGroup ) ) ;
318
+ groupNativeElement = groupDebugElement . nativeElement ;
319
+ groupInstance = groupDebugElement . injector . get ( MdRadioGroup ) ;
320
+ groupNgControl = groupDebugElement . injector . get ( NgControl ) ;
321
+
322
+ radioDebugElements = fixture . debugElement . queryAll ( By . directive ( MdRadioButton ) ) ;
323
+ radioNativeElements = radioDebugElements . map ( debugEl => debugEl . nativeElement ) ;
324
+ radioInstances = radioDebugElements . map ( debugEl => debugEl . componentInstance ) ;
325
+
326
+ fixture . detectChanges ( ) ;
327
+
328
+ spyOn ( testComponent , 'onChange' ) ;
329
+ } ) ;
330
+ } ) ) ;
331
+
332
+ it ( 'should update the model before firing change event' , fakeAsync ( ( ) => {
333
+ expect ( testComponent . modelValue ) . toBeUndefined ( ) ;
334
+
335
+ groupInstance . value = 'chocolate' ;
336
+ fixture . detectChanges ( ) ;
337
+
338
+ tick ( ) ;
339
+ expect ( testComponent . modelValue ) . toBe ( 'chocolate' ) ;
340
+ expect ( testComponent . onChange ) . toHaveBeenCalledWith ( 'chocolate' ) ;
341
+ } ) ) ;
342
+ } ) ;
343
+
300
344
describe ( 'as standalone' , ( ) => {
301
345
let fixture : ComponentFixture < StandaloneRadioButtons > ;
302
346
let radioDebugElements : DebugElement [ ] ;
@@ -388,7 +432,7 @@ class StandaloneRadioButtons { }
388
432
@Component ( {
389
433
directives : [ MD_RADIO_DIRECTIVES , FORM_DIRECTIVES ] ,
390
434
template : `
391
- <md-radio-group [(ngModel)]="modelValue">
435
+ <md-radio-group [(ngModel)]="modelValue" (change)="onChange(modelValue)" >
392
436
<md-radio-button *ngFor="let option of options" [value]="option.value">
393
437
{{option.label}}
394
438
</md-radio-button>
@@ -402,11 +446,11 @@ class RadioGroupWithNgModel {
402
446
{ label : 'Chocolate' , value : 'chocolate' } ,
403
447
{ label : 'Strawberry' , value : 'strawberry' } ,
404
448
] ;
449
+ onChange ( value : string ) { }
405
450
}
406
451
407
452
// TODO(jelbourn): remove eveything below when Angular supports faking events.
408
453
409
-
410
454
/**
411
455
* Dispatches a focus change event from an element.
412
456
* @param eventName Name of the event, either 'focus' or 'blur'.
0 commit comments