@@ -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,25 @@ 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 . value ) . toBe ( true ) ;
289+ expect ( testComponent . lastEvent . source ) . toBe ( checkboxInstance ) ;
292290 } ) ) ;
293291
294292 it ( 'should not emit a DOM event to the change output' , async ( ( ) => {
295- expect ( testComponent . handleChange ) . not . toHaveBeenCalled ( ) ;
293+ fixture . detectChanges ( ) ;
294+ expect ( testComponent . lastEvent ) . toBeUndefined ( ) ;
296295
297296 // Trigger the click on the inputElement, because the input will probably
298297 // emit a DOM event to the change output.
@@ -303,8 +302,8 @@ describe('MdCheckbox', () => {
303302 // We're checking the arguments type / emitted value to be a boolean, because sometimes the
304303 // emitted value can be a DOM Event, which is not valid.
305304 // See angular/angular#4059
306- expect ( testComponent . handleChange ) . toHaveBeenCalledTimes ( 1 ) ;
307- expect ( testComponent . handleChange ) . toHaveBeenCalledWith ( true ) ;
305+ expect ( testComponent . lastEvent . value ) . toBe ( true ) ;
306+ expect ( testComponent . lastEvent . source ) . toBe ( checkboxInstance ) ;
308307 } ) ;
309308
310309 } ) ) ;
@@ -541,8 +540,8 @@ class CheckboxWithNameAttribute {}
541540/** Simple test component with change event */
542541@Component ( {
543542 directives : [ MdCheckbox ] ,
544- template : `<md-checkbox (change)="handleChange( $event) "></md-checkbox>`
543+ template : `<md-checkbox (change)="lastEvent = $event"></md-checkbox>`
545544} )
546545class CheckboxWithChangeEvent {
547- handleChange ( value : boolean ) : void { }
546+ lastEvent : MdCheckboxChange ;
548547}
0 commit comments