Skip to content

Commit ef01eb0

Browse files
committed
fix(cdk/testing): fake touch event does not touch identifier
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`.
1 parent be76dc8 commit ef01eb0

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/cdk/testing/testbed/fake-events/event-objects.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export function createMouseEvent(
2727
const event = new MouseEvent(type, {
2828
bubbles: true,
2929
cancelable: true,
30+
view: window,
31+
detail: 0,
32+
relatedTarget: null,
3033
screenX,
3134
screenY,
3235
clientX,
@@ -77,7 +80,7 @@ export function createTouchEvent(type: string, pageX = 0, pageY = 0, clientX = 0
7780
// We cannot use the `TouchEvent` or `Touch` because Firefox and Safari lack support.
7881
// TODO: Switch to the constructor API when it is available for Firefox and Safari.
7982
const event = document.createEvent('UIEvent');
80-
const touchDetails = {pageX, pageY, clientX, clientY, id: uniqueIds++};
83+
const touchDetails = {pageX, pageY, clientX, clientY, identifier: uniqueIds++};
8184

8285
// TS3.6 removes the initUIEvent method and suggests porting to "new UIEvent()".
8386
(event as any).initUIEvent(type, true, true, window, 0);
@@ -98,15 +101,16 @@ export function createTouchEvent(type: string, pageX = 0, pageY = 0, clientX = 0
98101
export function createKeyboardEvent(type: string, keyCode: number = 0, key: string = '',
99102
modifiers: ModifierKeys = {}) {
100103
return new KeyboardEvent(type, {
101-
bubbles: true,
102-
cancelable: true,
103-
keyCode: keyCode,
104-
key: key,
105-
shiftKey: modifiers.shift,
106-
metaKey: modifiers.meta,
107-
altKey: modifiers.alt,
108-
ctrlKey: modifiers.control,
109-
});
104+
bubbles: true,
105+
cancelable: true,
106+
view: window,
107+
keyCode: keyCode,
108+
key: key,
109+
shiftKey: modifiers.shift,
110+
metaKey: modifiers.meta,
111+
altKey: modifiers.alt,
112+
ctrlKey: modifiers.control,
113+
});
110114
}
111115

112116
/**

0 commit comments

Comments
 (0)