Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
tinayuangao committed Feb 16, 2017
1 parent 9a27cd9 commit b1d58ce
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/lib/checkbox/checkbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@ import {FakeViewportRuler} from '../core/overlay/position/fake-viewport-ruler';
describe('MdCheckbox', () => {
let fixture: ComponentFixture<any>;

/** Creates a DOM mouse event. */
const createMouseEvent = (eventType: string, dict: any = {}) => {
// Ideally this would just be "return new MouseEvent(eventType, dict)". But IE11 doesn't support
// the MouseEvent constructor, and Edge inexplicably divides clientX and clientY by 100 to get
// pageX and pageY. (Really. After "e = new MouseEvent('click', {clientX: 200, clientY: 300})",
// e.clientX is 200, e.pageX is 2, e.clientY is 300, and e.pageY is 3.)
// So instead we use the deprecated createEvent/initMouseEvent API, which works everywhere.
const event = document.createEvent('MouseEvents');
event.initMouseEvent(eventType,
false, /* canBubble */
false, /* cancelable */
window, /* view */
0, /* detail */
dict.screenX || 0,
dict.screenY || 0,
dict.clientX || 0,
dict.clientY || 0,
false, /* ctrlKey */
false, /* altKey */
false, /* shiftKey */
false, /* metaKey */
0, /* button */
null /* relatedTarget */);
return event;
};

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MdCheckboxModule.forRoot(), FormsModule, ReactiveFormsModule],
Expand Down Expand Up @@ -388,7 +414,7 @@ describe('MdCheckbox', () => {
testComponent.isIndeterminate = true;
fixture.detectChanges();

inputElement.click();
inputElement.dispatchEvent(createMouseEvent('click'));
fixture.detectChanges();

expect(checkboxNativeElement.classList).not.toContain(
Expand Down

0 comments on commit b1d58ce

Please sign in to comment.