@@ -11,7 +11,7 @@ import {FORM_DIRECTIVES, NgModel, NgControl} from '@angular/common';
1111import { TestComponentBuilder , ComponentFixture } from '@angular/compiler/testing' ;
1212import { Component , DebugElement } from '@angular/core' ;
1313import { By } from '@angular/platform-browser' ;
14- import { MdCheckbox } from './checkbox' ;
14+ import { MdCheckbox , MdCheckboxChange } from './checkbox' ;
1515import { PromiseCompleter } from '@angular2-material/core/async/promise-completer' ;
1616
1717
@@ -273,26 +273,24 @@ describe('MdCheckbox', () => {
273273 testComponent = fixture . debugElement . componentInstance ;
274274 inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
275275 labelElement = < HTMLLabelElement > checkboxNativeElement . querySelector ( 'label' ) ;
276-
277- spyOn ( testComponent , 'handleChange' ) ;
278276 } ) ;
279277 } ) ) ;
280278
281279 it ( 'should call the change event on first change after initialization' , fakeAsync ( ( ) => {
282280 fixture . detectChanges ( ) ;
283- expect ( testComponent . handleChange ) . not . toHaveBeenCalled ( ) ;
281+ expect ( testComponent . lastEvent ) . toBeUndefined ( ) ;
284282
285283 checkboxInstance . checked = true ;
286284 fixture . detectChanges ( ) ;
287285
288286 tick ( ) ;
289287
290- expect ( testComponent . handleChange ) . toHaveBeenCalledTimes ( 1 ) ;
291- expect ( testComponent . handleChange ) . toHaveBeenCalledWith ( true ) ;
288+ expect ( testComponent . lastEvent . checked ) . toBe ( true ) ;
292289 } ) ) ;
293290
294291 it ( 'should not emit a DOM event to the change output' , async ( ( ) => {
295- expect ( testComponent . handleChange ) . not . toHaveBeenCalled ( ) ;
292+ fixture . detectChanges ( ) ;
293+ expect ( testComponent . lastEvent ) . toBeUndefined ( ) ;
296294
297295 // Trigger the click on the inputElement, because the input will probably
298296 // emit a DOM event to the change output.
@@ -303,8 +301,7 @@ describe('MdCheckbox', () => {
303301 // We're checking the arguments type / emitted value to be a boolean, because sometimes the
304302 // emitted value can be a DOM Event, which is not valid.
305303 // See angular/angular#4059
306- expect ( testComponent . handleChange ) . toHaveBeenCalledTimes ( 1 ) ;
307- expect ( testComponent . handleChange ) . toHaveBeenCalledWith ( true ) ;
304+ expect ( testComponent . lastEvent . checked ) . toBe ( true ) ;
308305 } ) ;
309306
310307 } ) ) ;
@@ -541,8 +538,8 @@ class CheckboxWithNameAttribute {}
541538/** Simple test component with change event */
542539@Component ( {
543540 directives : [ MdCheckbox ] ,
544- template : `<md-checkbox (change)="handleChange( $event) "></md-checkbox>`
541+ template : `<md-checkbox (change)="lastEvent = $event"></md-checkbox>`
545542} )
546543class CheckboxWithChangeEvent {
547- handleChange ( value : boolean ) : void { }
544+ lastEvent : MdCheckboxChange ;
548545}
0 commit comments