@@ -11,6 +11,32 @@ import {dispatchFakeEvent} from '../core/testing/dispatch-events';
11
11
describe ( 'MdCheckbox' , ( ) => {
12
12
let fixture : ComponentFixture < any > ;
13
13
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
+
14
40
beforeEach ( async ( ( ) => {
15
41
TestBed . configureTestingModule ( {
16
42
imports : [ MdCheckboxModule . forRoot ( ) , FormsModule , ReactiveFormsModule ] ,
@@ -416,7 +442,7 @@ describe('MdCheckbox', () => {
416
442
testComponent . isIndeterminate = true ;
417
443
fixture . detectChanges ( ) ;
418
444
419
- inputElement . click ( ) ;
445
+ inputElement . dispatchEvent ( createMouseEvent ( 'click' ) ) ;
420
446
fixture . detectChanges ( ) ;
421
447
422
448
expect ( checkboxNativeElement . classList ) . not . toContain (
0 commit comments