@@ -32,6 +32,7 @@ describe('MdCheckbox', () => {
32
32
CheckboxWithNameAttribute ,
33
33
CheckboxWithChangeEvent ,
34
34
CheckboxWithFormControl ,
35
+ CheckboxWithoutLabel ,
35
36
] ,
36
37
providers : [
37
38
{ provide : ViewportRuler , useClass : FakeViewportRuler }
@@ -436,28 +437,28 @@ describe('MdCheckbox', () => {
436
437
it ( 'should apply class based on color attribute' , ( ) => {
437
438
testComponent . checkboxColor = 'primary' ;
438
439
fixture . detectChanges ( ) ;
439
- expect ( checkboxDebugElement . nativeElement . classList . contains ( 'mat-primary' ) ) . toBe ( true ) ;
440
+ expect ( checkboxNativeElement . classList . contains ( 'mat-primary' ) ) . toBe ( true ) ;
440
441
441
442
testComponent . checkboxColor = 'accent' ;
442
443
fixture . detectChanges ( ) ;
443
- expect ( checkboxDebugElement . nativeElement . classList . contains ( 'mat-accent' ) ) . toBe ( true ) ;
444
+ expect ( checkboxNativeElement . classList . contains ( 'mat-accent' ) ) . toBe ( true ) ;
444
445
} ) ;
445
446
446
447
it ( 'should should not clear previous defined classes' , ( ) => {
447
- checkboxDebugElement . nativeElement . classList . add ( 'custom-class' ) ;
448
+ checkboxNativeElement . classList . add ( 'custom-class' ) ;
448
449
449
450
testComponent . checkboxColor = 'primary' ;
450
451
fixture . detectChanges ( ) ;
451
452
452
- expect ( checkboxDebugElement . nativeElement . classList . contains ( 'mat-primary' ) ) . toBe ( true ) ;
453
- expect ( checkboxDebugElement . nativeElement . classList . contains ( 'custom-class' ) ) . toBe ( true ) ;
453
+ expect ( checkboxNativeElement . classList . contains ( 'mat-primary' ) ) . toBe ( true ) ;
454
+ expect ( checkboxNativeElement . classList . contains ( 'custom-class' ) ) . toBe ( true ) ;
454
455
455
456
testComponent . checkboxColor = 'accent' ;
456
457
fixture . detectChanges ( ) ;
457
458
458
- expect ( checkboxDebugElement . nativeElement . classList . contains ( 'mat-primary' ) ) . toBe ( false ) ;
459
- expect ( checkboxDebugElement . nativeElement . classList . contains ( 'mat-accent' ) ) . toBe ( true ) ;
460
- expect ( checkboxDebugElement . nativeElement . classList . contains ( 'custom-class' ) ) . toBe ( true ) ;
459
+ expect ( checkboxNativeElement . classList . contains ( 'mat-primary' ) ) . toBe ( false ) ;
460
+ expect ( checkboxNativeElement . classList . contains ( 'mat-accent' ) ) . toBe ( true ) ;
461
+ expect ( checkboxNativeElement . classList . contains ( 'custom-class' ) ) . toBe ( true ) ;
461
462
462
463
} ) ;
463
464
} ) ;
@@ -730,7 +731,6 @@ describe('MdCheckbox', () => {
730
731
} ) ;
731
732
} ) ;
732
733
733
-
734
734
describe ( 'with form control' , ( ) => {
735
735
let checkboxDebugElement : DebugElement ;
736
736
let checkboxInstance : MdCheckbox ;
@@ -763,6 +763,22 @@ describe('MdCheckbox', () => {
763
763
expect ( inputElement . disabled ) . toBe ( false ) ;
764
764
} ) ;
765
765
} ) ;
766
+
767
+ describe ( 'without label' , ( ) => {
768
+ let checkboxDebugElement : DebugElement ;
769
+ let checkboxNativeElement : HTMLElement ;
770
+
771
+ it ( 'should add a css class to inner-container to remove side margin' , ( ) => {
772
+ fixture = TestBed . createComponent ( CheckboxWithoutLabel ) ;
773
+ fixture . detectChanges ( ) ;
774
+ checkboxDebugElement = fixture . debugElement . query ( By . directive ( MdCheckbox ) ) ;
775
+ checkboxNativeElement = checkboxDebugElement . nativeElement ;
776
+
777
+ let checkboxInnerContainerWithoutMarginCount = checkboxNativeElement
778
+ . querySelectorAll ( '.mat-checkbox-inner-container-no-side-margin' ) . length ;
779
+ expect ( checkboxInnerContainerWithoutMarginCount ) . toBe ( 1 ) ;
780
+ } ) ;
781
+ } ) ;
766
782
} ) ;
767
783
768
784
/** Simple component for testing a single checkbox. */
@@ -872,3 +888,9 @@ class CheckboxWithChangeEvent {
872
888
class CheckboxWithFormControl {
873
889
formControl = new FormControl ( ) ;
874
890
}
891
+
892
+ /** Test component without label */
893
+ @Component ( {
894
+ template : `<md-checkbox></md-checkbox>`
895
+ } )
896
+ class CheckboxWithoutLabel { }
0 commit comments