@@ -26,6 +26,7 @@ describe('MdCheckbox', () => {
2626 SingleCheckbox ,
2727 CheckboxWithFormDirectives ,
2828 MultipleCheckboxes ,
29+ CheckboxWithNgModel ,
2930 CheckboxWithTabIndex ,
3031 CheckboxWithAriaLabel ,
3132 CheckboxWithAriaLabelledby ,
@@ -735,6 +736,41 @@ describe('MdCheckbox', () => {
735736 } ) ;
736737 } ) ;
737738
739+ describe ( 'with required ngModel' , ( ) => {
740+ let checkboxInstance : MdCheckbox ;
741+ let inputElement : HTMLInputElement ;
742+ let testComponent : CheckboxWithNgModel ;
743+
744+ beforeEach ( ( ) => {
745+ fixture = TestBed . createComponent ( CheckboxWithNgModel ) ;
746+ fixture . detectChanges ( ) ;
747+
748+ let checkboxDebugElement = fixture . debugElement . query ( By . directive ( MdCheckbox ) ) ;
749+ let checkboxNativeElement = checkboxDebugElement . nativeElement ;
750+ testComponent = fixture . debugElement . componentInstance ;
751+ checkboxInstance = checkboxDebugElement . componentInstance ;
752+ inputElement = < HTMLInputElement > checkboxNativeElement . querySelector ( 'input' ) ;
753+ } ) ;
754+
755+ it ( 'should validate with RequiredTrue validator' , ( ) => {
756+ let checkboxElement = fixture . debugElement . query ( By . directive ( MdCheckbox ) ) ;
757+ let ngModel = checkboxElement . injector . get < NgModel > ( NgModel ) ;
758+
759+ testComponent . isRequired = true ;
760+ inputElement . click ( ) ;
761+ fixture . detectChanges ( ) ;
762+
763+ expect ( checkboxInstance . checked ) . toBe ( true ) ;
764+ expect ( ngModel . valid ) . toBe ( true ) ;
765+
766+ inputElement . click ( ) ;
767+ fixture . detectChanges ( ) ;
768+
769+ expect ( checkboxInstance . checked ) . toBe ( false ) ;
770+ expect ( ngModel . valid ) . toBe ( false ) ;
771+ } ) ;
772+ } ) ;
773+
738774 describe ( 'with name attribute' , ( ) => {
739775 beforeEach ( ( ) => {
740776 fixture = TestBed . createComponent ( CheckboxWithNameAttribute ) ;
@@ -874,7 +910,7 @@ class SingleCheckbox {
874910 onCheckboxChange : ( event ?: MdCheckboxChange ) => void = ( ) => { } ;
875911}
876912
877- /** Simple component for testing an MdCheckbox with ngModel. */
913+ /** Simple component for testing an MdCheckbox with ngModel in a form . */
878914@Component ( {
879915 template : `
880916 <form>
@@ -886,6 +922,15 @@ class CheckboxWithFormDirectives {
886922 isGood : boolean = false ;
887923}
888924
925+ /** Simple component for testing an MdCheckbox with required ngModel. */
926+ @Component ( {
927+ template : `<md-checkbox [required]="isRequired" [(ngModel)]="isGood">Be good</md-checkbox>` ,
928+ } )
929+ class CheckboxWithNgModel {
930+ isGood : boolean = false ;
931+ isRequired : boolean = true ;
932+ }
933+
889934/** Simple test component with multiple checkboxes. */
890935@Component ( ( {
891936 template : `
0 commit comments