@testing-library/user-event 14.0.0-alpha.8 → 14.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,6 +27,5 @@ export * from './misc/isDisabled';
27
27
  export * from './misc/wait';
28
28
  export * from './misc/hasPointerEvents';
29
29
  export * from './misc/hasFormSubmit';
30
- export * from './pointer/fakeEvent';
31
30
  export * from './pointer/firePointerEvents';
32
31
  export * from './pointer/mouseButtons';
@@ -381,19 +381,6 @@ Object.keys(_hasFormSubmit).forEach(function (key) {
381
381
  });
382
382
  });
383
383
 
384
- var _fakeEvent = require("./pointer/fakeEvent");
385
-
386
- Object.keys(_fakeEvent).forEach(function (key) {
387
- if (key === "default" || key === "__esModule") return;
388
- if (key in exports && exports[key] === _fakeEvent[key]) return;
389
- Object.defineProperty(exports, key, {
390
- enumerable: true,
391
- get: function () {
392
- return _fakeEvent[key];
393
- }
394
- });
395
- });
396
-
397
384
  var _firePointerEvents = require("./pointer/firePointerEvents");
398
385
 
399
386
  Object.keys(_firePointerEvents).forEach(function (key) {
@@ -1,6 +1,5 @@
1
1
  import type { pointerState } from '../../pointer/types';
2
2
  import type { keyboardState } from '../../keyboard/types';
3
- import { PointerCoords } from './fakeEvent';
4
3
  import { MouseButton } from './mouseButtons';
5
4
  export declare function firePointerEvent(target: Element, type: string, { pointerState, keyboardState, pointerType, button, coords, pointerId, isPrimary, clickCount, }: {
6
5
  pointerState: pointerState;
@@ -12,3 +11,15 @@ export declare function firePointerEvent(target: Element, type: string, { pointe
12
11
  isPrimary?: boolean;
13
12
  clickCount?: number;
14
13
  }): boolean;
14
+ export interface PointerCoords {
15
+ x?: number;
16
+ y?: number;
17
+ clientX?: number;
18
+ clientY?: number;
19
+ offsetX?: number;
20
+ offsetY?: number;
21
+ pageX?: number;
22
+ pageY?: number;
23
+ screenX?: number;
24
+ screenY?: number;
25
+ }
@@ -7,7 +7,7 @@ exports.firePointerEvent = firePointerEvent;
7
7
 
8
8
  var _dom = require("@testing-library/dom");
9
9
 
10
- var _fakeEvent = require("./fakeEvent");
10
+ var _eventMap = require("@testing-library/dom/dist/event-map");
11
11
 
12
12
  var _mouseButtons = require("./mouseButtons");
13
13
 
@@ -21,7 +21,6 @@ function firePointerEvent(target, type, {
21
21
  isPrimary,
22
22
  clickCount
23
23
  }) {
24
- const Event = type === 'click' || type.startsWith('mouse') ? _fakeEvent.FakeMouseEvent : _fakeEvent.FakePointerEvent;
25
24
  const init = { ...coords,
26
25
  altKey: keyboardState.modifiers.alt,
27
26
  ctrlKey: keyboardState.modifiers.ctrl,
@@ -29,7 +28,7 @@ function firePointerEvent(target, type, {
29
28
  shiftKey: keyboardState.modifiers.shift
30
29
  };
31
30
 
32
- if (Event === _fakeEvent.FakePointerEvent || type === 'click') {
31
+ if (type === 'click' || type.startsWith('pointer')) {
33
32
  init.pointerId = pointerId;
34
33
  init.pointerType = pointerType;
35
34
  }
@@ -47,9 +46,67 @@ function firePointerEvent(target, type, {
47
46
  }));
48
47
  }
49
48
 
50
- if (['mousedown', 'mouseup', 'click'].includes(type)) {
49
+ if (['mousedown', 'mouseup', 'click', 'dblclick'].includes(type)) {
51
50
  init.detail = clickCount;
52
51
  }
53
52
 
54
- return (0, _dom.fireEvent)(target, new Event(type, init));
53
+ const eventKey = Object.keys(_eventMap.eventMap).find(k => k.toLowerCase() === type);
54
+
55
+ const event = _dom.createEvent[eventKey](target, init); // see https://github.com/testing-library/react-testing-library/issues/268
56
+
57
+
58
+ assignPositionInit(event, init);
59
+ assignPointerInit(event, init);
60
+ return (0, _dom.fireEvent)(target, event);
61
+ }
62
+
63
+ function assignProps(obj, props) {
64
+ for (const [key, value] of Object.entries(props)) {
65
+ Object.defineProperty(obj, key, {
66
+ get: () => value
67
+ });
68
+ }
69
+ }
70
+
71
+ function assignPositionInit(obj, {
72
+ x,
73
+ y,
74
+ clientX,
75
+ clientY,
76
+ offsetX,
77
+ offsetY,
78
+ pageX,
79
+ pageY,
80
+ screenX,
81
+ screenY
82
+ }) {
83
+ var _ref, _ref2, _ref3, _ref4;
84
+
85
+ assignProps(obj, {
86
+ /* istanbul ignore start */
87
+ x: (_ref = x != null ? x : clientX) != null ? _ref : 0,
88
+ y: (_ref2 = y != null ? y : clientY) != null ? _ref2 : 0,
89
+ clientX: (_ref3 = x != null ? x : clientX) != null ? _ref3 : 0,
90
+ clientY: (_ref4 = y != null ? y : clientY) != null ? _ref4 : 0,
91
+ offsetX: offsetX != null ? offsetX : 0,
92
+ offsetY: offsetY != null ? offsetY : 0,
93
+ pageX: pageX != null ? pageX : 0,
94
+ pageY: pageY != null ? pageY : 0,
95
+ screenX: screenX != null ? screenX : 0,
96
+ screenY: screenY != null ? screenY : 0
97
+ /* istanbul ignore end */
98
+
99
+ });
100
+ }
101
+
102
+ function assignPointerInit(obj, {
103
+ isPrimary,
104
+ pointerId,
105
+ pointerType
106
+ }) {
107
+ assignProps(obj, {
108
+ isPrimary,
109
+ pointerId,
110
+ pointerType
111
+ });
55
112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.0.0-alpha.8",
3
+ "version": "14.0.0-alpha.9",
4
4
  "description": "Fire events the same way the user does",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [
@@ -1,20 +0,0 @@
1
- export interface PointerCoords {
2
- x?: number;
3
- y?: number;
4
- clientX?: number;
5
- clientY?: number;
6
- offsetX?: number;
7
- offsetY?: number;
8
- pageX?: number;
9
- pageY?: number;
10
- screenX?: number;
11
- screenY?: number;
12
- }
13
- export interface FakePointerEventInit extends MouseEventInit, PointerEventInit, PointerCoords {
14
- }
15
- export declare class FakeMouseEvent extends MouseEvent {
16
- constructor(type: string, init: FakePointerEventInit);
17
- }
18
- export declare class FakePointerEvent extends MouseEvent {
19
- constructor(type: string, init: FakePointerEventInit);
20
- }
@@ -1,91 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.FakePointerEvent = exports.FakeMouseEvent = void 0;
7
-
8
- // See : https://github.com/testing-library/react-testing-library/issues/268
9
- function assignProps(obj, props) {
10
- for (const [key, value] of Object.entries(props)) {
11
- Object.defineProperty(obj, key, {
12
- get: () => value
13
- });
14
- }
15
- }
16
-
17
- function assignPositionInit(obj, {
18
- x,
19
- y,
20
- clientX,
21
- clientY,
22
- offsetX,
23
- offsetY,
24
- pageX,
25
- pageY,
26
- screenX,
27
- screenY
28
- }) {
29
- var _ref, _ref2, _ref3, _ref4;
30
-
31
- assignProps(obj, {
32
- /* istanbul ignore start */
33
- x: (_ref = x != null ? x : clientX) != null ? _ref : 0,
34
- y: (_ref2 = y != null ? y : clientY) != null ? _ref2 : 0,
35
- clientX: (_ref3 = x != null ? x : clientX) != null ? _ref3 : 0,
36
- clientY: (_ref4 = y != null ? y : clientY) != null ? _ref4 : 0,
37
- offsetX: offsetX != null ? offsetX : 0,
38
- offsetY: offsetY != null ? offsetY : 0,
39
- pageX: pageX != null ? pageX : 0,
40
- pageY: pageY != null ? pageY : 0,
41
- screenX: screenX != null ? screenX : 0,
42
- screenY: screenY != null ? screenY : 0
43
- /* istanbul ignore end */
44
-
45
- });
46
- }
47
-
48
- function assignPointerInit(obj, {
49
- isPrimary,
50
- pointerId,
51
- pointerType
52
- }) {
53
- assignProps(obj, {
54
- isPrimary,
55
- pointerId,
56
- pointerType
57
- });
58
- }
59
-
60
- const notBubbling = ['mouseenter', 'mouseleave', 'pointerenter', 'pointerleave'];
61
-
62
- function getInitDefaults(type, init) {
63
- return {
64
- bubbles: !notBubbling.includes(type),
65
- cancelable: true,
66
- composed: true,
67
- ...init
68
- };
69
- }
70
-
71
- class FakeMouseEvent extends MouseEvent {
72
- constructor(type, init) {
73
- super(type, getInitDefaults(type, init));
74
- assignPositionInit(this, init);
75
- }
76
-
77
- } // Should extend PointerEvent, but... https://github.com/jsdom/jsdom/issues/2527
78
-
79
-
80
- exports.FakeMouseEvent = FakeMouseEvent;
81
-
82
- class FakePointerEvent extends MouseEvent {
83
- constructor(type, init) {
84
- super(type, getInitDefaults(type, init));
85
- assignPositionInit(this, init);
86
- assignPointerInit(this, init);
87
- }
88
-
89
- }
90
-
91
- exports.FakePointerEvent = FakePointerEvent;