Skip to content

Commit

Permalink
fix(cdk/testing): fake touch event does not set proper touch identifier
Browse files Browse the repository at this point in the history
The fake `TouchEvent` being created by test harnesses for the
TestBed harness environment currently set an id for a `Touch`
of the fake event. The `Touch` currently incorrectly sets the
unique touch id to a field named `id`, while it should be `identifier`.
  • Loading branch information
devversion authored and amysorto committed Aug 20, 2021
1 parent cb06582 commit 692ebaf
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/cdk/testing/testbed/fake-events/event-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export function createMouseEvent(
const event = new MouseEvent(type, {
bubbles: true,
cancelable: true,
view: window,
detail: 0,
relatedTarget: null,
screenX,
screenY,
clientX,
Expand Down Expand Up @@ -77,7 +80,7 @@ export function createTouchEvent(type: string, pageX = 0, pageY = 0, clientX = 0
// We cannot use the `TouchEvent` or `Touch` because Firefox and Safari lack support.
// TODO: Switch to the constructor API when it is available for Firefox and Safari.
const event = document.createEvent('UIEvent');
const touchDetails = {pageX, pageY, clientX, clientY, id: uniqueIds++};
const touchDetails = {pageX, pageY, clientX, clientY, identifier: uniqueIds++};

// TS3.6 removes the initUIEvent method and suggests porting to "new UIEvent()".
(event as any).initUIEvent(type, true, true, window, 0);
Expand All @@ -98,15 +101,16 @@ export function createTouchEvent(type: string, pageX = 0, pageY = 0, clientX = 0
export function createKeyboardEvent(type: string, keyCode: number = 0, key: string = '',
modifiers: ModifierKeys = {}) {
return new KeyboardEvent(type, {
bubbles: true,
cancelable: true,
keyCode: keyCode,
key: key,
shiftKey: modifiers.shift,
metaKey: modifiers.meta,
altKey: modifiers.alt,
ctrlKey: modifiers.control,
});
bubbles: true,
cancelable: true,
view: window,
keyCode: keyCode,
key: key,
shiftKey: modifiers.shift,
metaKey: modifiers.meta,
altKey: modifiers.alt,
ctrlKey: modifiers.control,
});
}

/**
Expand Down

0 comments on commit 692ebaf

Please sign in to comment.