Skip to content

Commit 9c13e99

Browse files
committed
.
1 parent 7ffbc4f commit 9c13e99

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/lib/checkbox/checkbox.spec.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@ import {dispatchFakeEvent} from '../core/testing/dispatch-events';
1111
describe('MdCheckbox', () => {
1212
let fixture: ComponentFixture<any>;
1313

14+
/** Creates a DOM mouse event. */
15+
const createMouseEvent = (eventType: string, dict: any = {}) => {
16+
// Ideally this would just be "return new MouseEvent(eventType, dict)". But IE11 doesn't support
17+
// the MouseEvent constructor, and Edge inexplicably divides clientX and clientY by 100 to get
18+
// pageX and pageY. (Really. After "e = new MouseEvent('click', {clientX: 200, clientY: 300})",
19+
// e.clientX is 200, e.pageX is 2, e.clientY is 300, and e.pageY is 3.)
20+
// So instead we use the deprecated createEvent/initMouseEvent API, which works everywhere.
21+
const event = document.createEvent('MouseEvents');
22+
event.initMouseEvent(eventType,
23+
false, /* canBubble */
24+
false, /* cancelable */
25+
window, /* view */
26+
0, /* detail */
27+
dict.screenX || 0,
28+
dict.screenY || 0,
29+
dict.clientX || 0,
30+
dict.clientY || 0,
31+
false, /* ctrlKey */
32+
false, /* altKey */
33+
false, /* shiftKey */
34+
false, /* metaKey */
35+
0, /* button */
36+
null /* relatedTarget */);
37+
return event;
38+
};
39+
1440
beforeEach(async(() => {
1541
TestBed.configureTestingModule({
1642
imports: [MdCheckboxModule.forRoot(), FormsModule, ReactiveFormsModule],
@@ -416,7 +442,7 @@ describe('MdCheckbox', () => {
416442
testComponent.isIndeterminate = true;
417443
fixture.detectChanges();
418444

419-
inputElement.click();
445+
inputElement.dispatchEvent(createMouseEvent('click'));
420446
fixture.detectChanges();
421447

422448
expect(checkboxNativeElement.classList).not.toContain(

0 commit comments

Comments
 (0)