Skip to content

Commit d9f0025

Browse files
committed
Fix nested checkbox demo and update test name
Fixes #575.
1 parent b2471f2 commit d9f0025

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/components/checkbox/checkbox.spec.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,33 @@ describe('MdCheckbox', () => {
214214
expect(testComponent.onCheckboxClick).toHaveBeenCalledTimes(1);
215215
});
216216

217-
it('should emit a change event when the `checked` value changes', async(() => {
217+
it('should trigger a change event when the native input does', async(() => {
218+
spyOn(testComponent, 'onCheckboxChange');
219+
220+
expect(inputElement.checked).toBe(false);
221+
expect(checkboxNativeElement.classList).not.toContain('md-checkbox-checked');
222+
223+
labelElement.click();
224+
fixture.detectChanges();
225+
226+
expect(inputElement.checked).toBe(true);
227+
expect(checkboxNativeElement.classList).toContain('md-checkbox-checked');
228+
229+
// Wait for the fixture to become stable, because the EventEmitter for the change event,
230+
// will only fire after the zone async change detection has finished.
231+
fixture.whenStable().then(() => {
232+
// The change event shouldn't fire, because the value change was not caused
233+
// by any interaction.
234+
expect(testComponent.onCheckboxChange).toHaveBeenCalledTimes(1);
235+
});
236+
}));
237+
238+
it('should not trigger the change event by changing the native value', async(() => {
239+
spyOn(testComponent, 'onCheckboxChange');
240+
241+
expect(inputElement.checked).toBe(false);
242+
expect(checkboxNativeElement.classList).not.toContain('md-checkbox-checked');
243+
218244
testComponent.isChecked = true;
219245
fixture.detectChanges();
220246

src/demo-app/checkbox/checkbox-demo.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,5 @@ <h1>md-checkbox: Basic Example</h1>
4040
</div>
4141
</div>
4242

43-
<h1>Application Example: Nested Checklist</h1>
44-
<h2><em>Caution: WIP!</em></h2>
45-
<md-checkbox-demo-nested-checklist></md-checkbox-demo-nested-checklist>
43+
<h1>Nested Checklist</h1>
44+
<md-checkbox-demo-nested-checklist></md-checkbox-demo-nested-checklist>

src/demo-app/checkbox/nested-checklist.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ <h2>Tasks</h2>
44
<md-checkbox [(ngModel)]="task.completed"
55
[checked]="allComplete(task)"
66
[indeterminate]="someComplete(task.subtasks)"
7-
(change)="setAllCompleted(task.subtasks, $event)">
7+
(change)="setAllCompleted(task.subtasks, $event.checked)">
88
<h3>{{task.name}}</h3>
99
</md-checkbox>
1010
<ul>

0 commit comments

Comments
 (0)