1- import {
2- async ,
3- fakeAsync ,
4- flushMicrotasks ,
5- ComponentFixture ,
6- TestBed ,
7- } from '@angular/core/testing' ;
8- import {
9- NgControl ,
10- FormsModule ,
11- ReactiveFormsModule ,
12- FormControl ,
13- } from '@angular/forms' ;
1+ import { async , fakeAsync , flushMicrotasks , ComponentFixture , TestBed } from '@angular/core/testing' ;
2+ import { NgControl , FormsModule , ReactiveFormsModule , FormControl } from '@angular/forms' ;
143import { Component , DebugElement } from '@angular/core' ;
154import { By } from '@angular/platform-browser' ;
165import { MdCheckbox , MdCheckboxChange , MdCheckboxModule } from './checkbox' ;
176import { ViewportRuler } from '../core/overlay/position/viewport-ruler' ;
187import { FakeViewportRuler } from '../core/overlay/position/fake-viewport-ruler' ;
198
209
21-
2210describe ( 'MdCheckbox' , ( ) => {
2311 let fixture : ComponentFixture < any > ;
2412
@@ -586,9 +574,19 @@ describe('MdCheckbox', () => {
586574 } ) ;
587575
588576 describe ( 'with ngModel' , ( ) => {
577+ let checkboxDebugElement : DebugElement ;
578+ let checkboxNativeElement : HTMLElement ;
579+ let checkboxInstance : MdCheckbox ;
580+ let inputElement : HTMLInputElement ;
581+
589582 beforeEach ( ( ) => {
590583 fixture = TestBed . createComponent ( CheckboxWithFormDirectives ) ;
591584 fixture . detectChanges ( ) ;
585+
586+ checkboxDebugElement = fixture . debugElement . query ( By . directive ( MdCheckbox ) ) ;
587+ checkboxNativeElement = checkboxDebugElement . nativeElement ;
588+ checkboxInstance = checkboxDebugElement . componentInstance ;
589+ inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
592590 } ) ;
593591
594592 it ( 'should be in pristine, untouched, and valid states initially' , fakeAsync ( ( ) => {
@@ -604,6 +602,20 @@ describe('MdCheckbox', () => {
604602 // TODO(jelbourn): test that `touched` and `pristine` state are modified appropriately.
605603 // This is currently blocked on issues with async() and fakeAsync().
606604 } ) ) ;
605+
606+ it ( 'should toggle checked state on click' , ( ) => {
607+ expect ( checkboxInstance . checked ) . toBe ( false ) ;
608+
609+ inputElement . click ( ) ;
610+ fixture . detectChanges ( ) ;
611+
612+ expect ( checkboxInstance . checked ) . toBe ( true ) ;
613+
614+ inputElement . click ( ) ;
615+ fixture . detectChanges ( ) ;
616+
617+ expect ( checkboxInstance . checked ) . toBe ( false ) ;
618+ } ) ;
607619 } ) ;
608620
609621 describe ( 'with name attribute' , ( ) => {
0 commit comments