@@ -297,6 +297,50 @@ describe('MdRadio', () => {
297297 } ) ) ;
298298 } ) ;
299299
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+
300344 describe ( 'as standalone' , ( ) => {
301345 let fixture : ComponentFixture < StandaloneRadioButtons > ;
302346 let radioDebugElements : DebugElement [ ] ;
@@ -388,7 +432,7 @@ class StandaloneRadioButtons { }
388432@Component ( {
389433 directives : [ MD_RADIO_DIRECTIVES , FORM_DIRECTIVES ] ,
390434 template : `
391- <md-radio-group [(ngModel)]="modelValue">
435+ <md-radio-group [(ngModel)]="modelValue" (change)="onChange(modelValue)" >
392436 <md-radio-button *ngFor="let option of options" [value]="option.value">
393437 {{option.label}}
394438 </md-radio-button>
@@ -402,11 +446,11 @@ class RadioGroupWithNgModel {
402446 { label : 'Chocolate' , value : 'chocolate' } ,
403447 { label : 'Strawberry' , value : 'strawberry' } ,
404448 ] ;
449+ onChange ( value : string ) { }
405450}
406451
407452// TODO(jelbourn): remove eveything below when Angular supports faking events.
408453
409-
410454/**
411455 * Dispatches a focus change event from an element.
412456 * @param eventName Name of the event, either 'focus' or 'blur'.
0 commit comments