Skip to content

Commit 2f60f2b

Browse files
committed
refactor(material-experimental/checkbox): change test for double-clicking
refactor the 'should not trigger the click event multiple times' test by listening for changes on the parent of the mdc-checkbox rather than the mdc-checkbox itself
1 parent cc5326c commit 2f60f2b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/material-experimental/mdc-checkbox/checkbox.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ describe('MDC-based MatCheckbox', () => {
312312
// Since we're using a label element and a visual hidden input, this behavior can led
313313
// to an issue, where the click events on the checkbox are getting executed twice.
314314

315-
spyOn(testComponent, 'onCheckboxClick');
315+
spyOn(testComponent, 'onParentElementClick');
316316

317317
expect(inputElement.checked).toBe(false);
318318

@@ -321,7 +321,7 @@ describe('MDC-based MatCheckbox', () => {
321321
flush();
322322

323323
expect(inputElement.checked).toBe(true);
324-
expect(testComponent.onCheckboxClick).toHaveBeenCalledTimes(1);
324+
expect(testComponent.onParentElementClick).toHaveBeenCalledTimes(1);
325325
}));
326326

327327
it('should trigger a change event when the native input does', fakeAsync(() => {
@@ -1034,7 +1034,7 @@ describe('MatCheckboxDefaultOptions', () => {
10341034
/** Simple component for testing a single checkbox. */
10351035
@Component({
10361036
template: `
1037-
<div (click)="parentElementClicked = true" (keyup)="parentElementKeyedUp = true">
1037+
<div (click)="parentElementClicked = true; onParentElementClick($event)" (keyup)="parentElementKeyedUp = true">
10381038
<mat-checkbox
10391039
[id]="checkboxId"
10401040
[required]="isRequired"
@@ -1066,6 +1066,7 @@ class SingleCheckbox {
10661066

10671067
onCheckboxClick: (event?: Event) => void = () => {};
10681068
onCheckboxChange: (event?: MatCheckboxChange) => void = () => {};
1069+
onParentElementClick: (event?: Event) => void = () => {};
10691070
}
10701071

10711072
/** Simple component for testing an MatCheckbox with required ngModel. */

0 commit comments

Comments
 (0)