diff --git a/e2e/components/checkbox-e2e.spec.ts b/e2e/components/checkbox-e2e.spec.ts index 2256bf712043..4d4988f04a76 100644 --- a/e2e/components/checkbox-e2e.spec.ts +++ b/e2e/components/checkbox-e2e.spec.ts @@ -9,7 +9,7 @@ describe('checkbox', () => { it('should be checked when clicked, and unchecked when clicked again', async () => { let checkboxEl = element(by.id('test-checkbox')); - let inputEl = element(by.css('input[id=input-test-checkbox]')); + let inputEl = element(by.css('input[id=test-checkbox-input]')); screenshot('start'); checkboxEl.click(); @@ -32,7 +32,7 @@ describe('checkbox', () => { }); it('should toggle the checkbox when pressing space', () => { - let inputEl = element(by.css('input[id=input-test-checkbox]')); + let inputEl = element(by.css('input[id=test-checkbox-input]')); expect(inputEl.getAttribute('checked')) .toBeFalsy('Expect checkbox "checked" property to be false'); diff --git a/src/lib/checkbox/checkbox.spec.ts b/src/lib/checkbox/checkbox.spec.ts index 5ccecf52af5f..0fb39a761746 100644 --- a/src/lib/checkbox/checkbox.spec.ts +++ b/src/lib/checkbox/checkbox.spec.ts @@ -266,6 +266,15 @@ describe('MdCheckbox', () => { it('should preserve the user-provided id', () => { expect(checkboxNativeElement.id).toBe('simple-check'); + expect(inputElement.id).toBe('simple-check-input'); + }); + + it('should generate a unique id for the checkbox input if no id is set', () => { + testComponent.checkboxId = null; + fixture.detectChanges(); + + expect(checkboxInstance.inputId).toMatch(/md-checkbox-\d+/); + expect(inputElement.id).toBe(checkboxInstance.inputId); }); it('should project the checkbox content into the label element', () => { @@ -675,8 +684,8 @@ describe('MdCheckbox', () => { fixture.debugElement.queryAll(By.directive(MdCheckbox)) .map(debugElement => debugElement.nativeElement.querySelector('input').id); - expect(firstId).toBeTruthy(); - expect(secondId).toBeTruthy(); + expect(firstId).toMatch(/md-checkbox-\d+-input/); + expect(secondId).toMatch(/md-checkbox-\d+-input/); expect(firstId).not.toEqual(secondId); }); }); @@ -833,7 +842,7 @@ describe('MdCheckbox', () => { template: `