@testing-library/user-event 14.0.0-alpha.7 → 14.0.0-beta.2

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.
Files changed (118) hide show
  1. package/dist/clipboard/copy.d.ts +2 -0
  2. package/dist/clipboard/copy.js +36 -0
  3. package/dist/clipboard/cut.d.ts +2 -0
  4. package/dist/clipboard/cut.js +42 -0
  5. package/dist/clipboard/index.d.ts +3 -0
  6. package/dist/clipboard/index.js +44 -0
  7. package/dist/clipboard/paste.d.ts +2 -0
  8. package/dist/clipboard/paste.js +47 -0
  9. package/dist/convenience/click.d.ts +4 -0
  10. package/dist/convenience/click.js +52 -0
  11. package/dist/convenience/hover.d.ts +3 -0
  12. package/dist/convenience/hover.js +31 -0
  13. package/dist/convenience/index.d.ts +3 -0
  14. package/dist/convenience/index.js +44 -0
  15. package/dist/convenience/tab.d.ts +4 -0
  16. package/dist/convenience/tab.js +12 -0
  17. package/dist/index.d.ts +2 -7
  18. package/dist/index.js +3 -12
  19. package/dist/keyboard/getEventProps.d.ts +0 -2
  20. package/dist/keyboard/getEventProps.js +1 -7
  21. package/dist/keyboard/index.d.ts +6 -18
  22. package/dist/keyboard/index.js +9 -45
  23. package/dist/keyboard/keyMap.js +24 -48
  24. package/dist/keyboard/keyboardAction.d.ts +10 -0
  25. package/dist/keyboard/keyboardAction.js +156 -0
  26. package/dist/keyboard/{getNextKeyDef.d.ts → parseKeyDef.d.ts} +4 -6
  27. package/dist/keyboard/parseKeyDef.js +61 -0
  28. package/dist/keyboard/plugins/character.js +21 -14
  29. package/dist/keyboard/plugins/combination.d.ts +5 -0
  30. package/dist/keyboard/plugins/combination.js +19 -0
  31. package/dist/keyboard/plugins/functional.js +38 -20
  32. package/dist/keyboard/plugins/index.d.ts +0 -1
  33. package/dist/keyboard/plugins/index.js +4 -11
  34. package/dist/keyboard/types.d.ts +3 -19
  35. package/dist/options.d.ts +102 -0
  36. package/dist/options.js +36 -0
  37. package/dist/pointer/index.d.ts +6 -14
  38. package/dist/pointer/index.js +8 -42
  39. package/dist/pointer/parseKeyDef.d.ts +2 -2
  40. package/dist/pointer/parseKeyDef.js +1 -3
  41. package/dist/pointer/pointerAction.d.ts +3 -2
  42. package/dist/pointer/pointerAction.js +9 -15
  43. package/dist/pointer/pointerMove.d.ts +2 -1
  44. package/dist/pointer/pointerPress.d.ts +2 -1
  45. package/dist/pointer/types.d.ts +0 -11
  46. package/dist/setup/api.d.ts +5 -0
  47. package/dist/setup/api.js +111 -0
  48. package/dist/setup/config.d.ts +10 -0
  49. package/dist/setup/config.js +8 -0
  50. package/dist/setup/directApi.d.ts +20 -0
  51. package/dist/setup/directApi.js +95 -0
  52. package/dist/setup/index.d.ts +30 -0
  53. package/dist/setup/index.js +27 -0
  54. package/dist/setup/setup.d.ts +74 -0
  55. package/dist/setup/setup.js +98 -0
  56. package/dist/setup/wrapAsync.d.ts +4 -0
  57. package/dist/setup/wrapAsync.js +15 -0
  58. package/dist/{clear.d.ts → utility/clear.d.ts} +2 -2
  59. package/dist/utility/clear.js +30 -0
  60. package/dist/utility/index.d.ts +4 -0
  61. package/dist/utility/index.js +57 -0
  62. package/dist/utility/selectOptions.d.ts +3 -0
  63. package/dist/{selectOptions.js → utility/selectOptions.js} +31 -41
  64. package/dist/utility/type.d.ts +9 -0
  65. package/dist/utility/type.js +37 -0
  66. package/dist/utility/upload.d.ts +5 -0
  67. package/dist/{upload.js → utility/upload.js} +12 -40
  68. package/dist/utils/dataTransfer/Blob.d.ts +1 -0
  69. package/dist/utils/dataTransfer/Blob.js +21 -0
  70. package/dist/utils/dataTransfer/Clipboard.d.ts +9 -0
  71. package/dist/utils/dataTransfer/Clipboard.js +188 -0
  72. package/dist/utils/dataTransfer/DataTransfer.d.ts +2 -0
  73. package/dist/utils/dataTransfer/DataTransfer.js +158 -0
  74. package/dist/utils/dataTransfer/FileList.d.ts +1 -0
  75. package/dist/utils/dataTransfer/FileList.js +23 -0
  76. package/dist/utils/edit/calculateNewValue.d.ts +1 -3
  77. package/dist/utils/edit/calculateNewValue.js +1 -5
  78. package/dist/utils/edit/editInputElement.d.ts +16 -0
  79. package/dist/utils/edit/{fireInputEvent.js → editInputElement.js} +8 -20
  80. package/dist/utils/edit/prepareInput.d.ts +4 -1
  81. package/dist/utils/edit/prepareInput.js +56 -39
  82. package/dist/utils/edit/setFiles.d.ts +12 -0
  83. package/dist/utils/edit/setFiles.js +72 -0
  84. package/dist/utils/focus/copySelection.d.ts +1 -0
  85. package/dist/utils/focus/copySelection.js +36 -0
  86. package/dist/utils/focus/selectAll.d.ts +5 -0
  87. package/dist/utils/focus/selectAll.js +51 -0
  88. package/dist/utils/index.d.ts +9 -2
  89. package/dist/utils/index.js +108 -17
  90. package/dist/utils/misc/getDocumentFromNode.d.ts +1 -0
  91. package/dist/utils/misc/getDocumentFromNode.js +14 -0
  92. package/dist/utils/misc/isVisible.js +8 -1
  93. package/dist/utils/pointer/firePointerEvents.d.ts +12 -1
  94. package/dist/utils/pointer/firePointerEvents.js +62 -5
  95. package/package.json +1 -1
  96. package/dist/clear.js +0 -46
  97. package/dist/click.d.ts +0 -9
  98. package/dist/click.js +0 -62
  99. package/dist/hover.d.ts +0 -4
  100. package/dist/hover.js +0 -43
  101. package/dist/keyboard/getNextKeyDef.js +0 -85
  102. package/dist/keyboard/keyboardImplementation.d.ts +0 -3
  103. package/dist/keyboard/keyboardImplementation.js +0 -169
  104. package/dist/keyboard/specialCharMap.d.ts +0 -22
  105. package/dist/keyboard/specialCharMap.js +0 -30
  106. package/dist/paste.d.ts +0 -7
  107. package/dist/paste.js +0 -60
  108. package/dist/selectOptions.d.ts +0 -4
  109. package/dist/setup.d.ts +0 -92
  110. package/dist/setup.js +0 -203
  111. package/dist/tab.d.ts +0 -5
  112. package/dist/tab.js +0 -12
  113. package/dist/type.d.ts +0 -14
  114. package/dist/type.js +0 -74
  115. package/dist/upload.d.ts +0 -10
  116. package/dist/utils/edit/fireInputEvent.d.ts +0 -11
  117. package/dist/utils/pointer/fakeEvent.d.ts +0 -20
  118. package/dist/utils/pointer/fakeEvent.js +0 -91
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.copySelection = copySelection;
7
+
8
+ var _document = require("../../document");
9
+
10
+ var _DataTransfer = require("../dataTransfer/DataTransfer");
11
+
12
+ var _selection = require("./selection");
13
+
14
+ function copySelection(target) {
15
+ const data = (0, _selection.hasOwnSelection)(target) ? {
16
+ 'text/plain': readSelectedValueFromInput(target)
17
+ } : // TODO: We could implement text/html copying of DOM nodes here
18
+ {
19
+ 'text/plain': String(target.ownerDocument.getSelection())
20
+ };
21
+ const dt = (0, _DataTransfer.createDataTransfer)();
22
+
23
+ for (const type in data) {
24
+ if (data[type]) {
25
+ dt.setData(type, data[type]);
26
+ }
27
+ }
28
+
29
+ return dt;
30
+ }
31
+
32
+ function readSelectedValueFromInput(target) {
33
+ const sel = (0, _document.getUISelection)(target);
34
+ const val = (0, _document.getUIValue)(target);
35
+ return val.substring(sel.startOffset, sel.endOffset);
36
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Expand a selection like the browser does when pressing Ctrl+A.
3
+ */
4
+ export declare function selectAll(target: Element): void;
5
+ export declare function isAllSelected(target: Element): boolean;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isAllSelected = isAllSelected;
7
+ exports.selectAll = selectAll;
8
+
9
+ var _document = require("../../document");
10
+
11
+ var _isContentEditable = require("../edit/isContentEditable");
12
+
13
+ var _isEditable = require("../edit/isEditable");
14
+
15
+ var _isElementType = require("../misc/isElementType");
16
+
17
+ var _selection = require("./selection");
18
+
19
+ /**
20
+ * Expand a selection like the browser does when pressing Ctrl+A.
21
+ */
22
+ function selectAll(target) {
23
+ var _getContentEditable;
24
+
25
+ if ((0, _isElementType.isElementType)(target, 'textarea') || (0, _isElementType.isElementType)(target, 'input') && target.type in _isEditable.editableInputTypes) {
26
+ return (0, _selection.setSelection)({
27
+ focusNode: target,
28
+ anchorOffset: 0,
29
+ focusOffset: (0, _document.getUIValue)(target).length
30
+ });
31
+ }
32
+
33
+ const focusNode = (_getContentEditable = (0, _isContentEditable.getContentEditable)(target)) != null ? _getContentEditable : target.ownerDocument.body;
34
+ (0, _selection.setSelection)({
35
+ focusNode,
36
+ anchorOffset: 0,
37
+ focusOffset: focusNode.childNodes.length
38
+ });
39
+ }
40
+
41
+ function isAllSelected(target) {
42
+ var _getContentEditable2;
43
+
44
+ if ((0, _isElementType.isElementType)(target, 'textarea') || (0, _isElementType.isElementType)(target, 'input') && target.type in _isEditable.editableInputTypes) {
45
+ return (0, _document.getUISelection)(target).startOffset === 0 && (0, _document.getUISelection)(target).endOffset === (0, _document.getUIValue)(target).length;
46
+ }
47
+
48
+ const focusNode = (_getContentEditable2 = (0, _isContentEditable.getContentEditable)(target)) != null ? _getContentEditable2 : target.ownerDocument.body;
49
+ const selection = target.ownerDocument.getSelection();
50
+ return (selection == null ? void 0 : selection.anchorNode) === focusNode && selection.focusNode === focusNode && selection.anchorOffset === 0 && selection.focusOffset === focusNode.childNodes.length;
51
+ }
@@ -1,7 +1,11 @@
1
1
  export * from './click/isClickableInput';
2
+ export * from './dataTransfer/Blob';
3
+ export * from './dataTransfer/DataTransfer';
4
+ export * from './dataTransfer/FileList';
5
+ export * from './dataTransfer/Clipboard';
2
6
  export * from './edit/buildTimeValue';
3
7
  export * from './edit/calculateNewValue';
4
- export * from './edit/fireInputEvent';
8
+ export * from './edit/editInputElement';
5
9
  export * from './edit/getValue';
6
10
  export * from './edit/isContentEditable';
7
11
  export * from './edit/isEditable';
@@ -9,16 +13,20 @@ export * from './edit/isValidDateValue';
9
13
  export * from './edit/isValidInputTimeValue';
10
14
  export * from './edit/maxLength';
11
15
  export * from './edit/prepareInput';
16
+ export * from './edit/setFiles';
12
17
  export * from './focus/blur';
18
+ export * from './focus/copySelection';
13
19
  export * from './focus/focus';
14
20
  export * from './focus/getActiveElement';
15
21
  export * from './focus/getTabDestination';
16
22
  export * from './focus/isFocusable';
23
+ export * from './focus/selectAll';
17
24
  export * from './focus/selection';
18
25
  export * from './focus/selector';
19
26
  export * from './keyDef/readNextDescriptor';
20
27
  export * from './misc/eventWrapper';
21
28
  export * from './misc/findClosest';
29
+ export * from './misc/getDocumentFromNode';
22
30
  export * from './misc/isDescendantOrSelf';
23
31
  export * from './misc/isElementType';
24
32
  export * from './misc/isVisible';
@@ -26,6 +34,5 @@ export * from './misc/isDisabled';
26
34
  export * from './misc/wait';
27
35
  export * from './misc/hasPointerEvents';
28
36
  export * from './misc/hasFormSubmit';
29
- export * from './pointer/fakeEvent';
30
37
  export * from './pointer/firePointerEvents';
31
38
  export * from './pointer/mouseButtons';
@@ -17,6 +17,58 @@ Object.keys(_isClickableInput).forEach(function (key) {
17
17
  });
18
18
  });
19
19
 
20
+ var _Blob = require("./dataTransfer/Blob");
21
+
22
+ Object.keys(_Blob).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _Blob[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _Blob[key];
29
+ }
30
+ });
31
+ });
32
+
33
+ var _DataTransfer = require("./dataTransfer/DataTransfer");
34
+
35
+ Object.keys(_DataTransfer).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (key in exports && exports[key] === _DataTransfer[key]) return;
38
+ Object.defineProperty(exports, key, {
39
+ enumerable: true,
40
+ get: function () {
41
+ return _DataTransfer[key];
42
+ }
43
+ });
44
+ });
45
+
46
+ var _FileList = require("./dataTransfer/FileList");
47
+
48
+ Object.keys(_FileList).forEach(function (key) {
49
+ if (key === "default" || key === "__esModule") return;
50
+ if (key in exports && exports[key] === _FileList[key]) return;
51
+ Object.defineProperty(exports, key, {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _FileList[key];
55
+ }
56
+ });
57
+ });
58
+
59
+ var _Clipboard = require("./dataTransfer/Clipboard");
60
+
61
+ Object.keys(_Clipboard).forEach(function (key) {
62
+ if (key === "default" || key === "__esModule") return;
63
+ if (key in exports && exports[key] === _Clipboard[key]) return;
64
+ Object.defineProperty(exports, key, {
65
+ enumerable: true,
66
+ get: function () {
67
+ return _Clipboard[key];
68
+ }
69
+ });
70
+ });
71
+
20
72
  var _buildTimeValue = require("./edit/buildTimeValue");
21
73
 
22
74
  Object.keys(_buildTimeValue).forEach(function (key) {
@@ -43,15 +95,15 @@ Object.keys(_calculateNewValue).forEach(function (key) {
43
95
  });
44
96
  });
45
97
 
46
- var _fireInputEvent = require("./edit/fireInputEvent");
98
+ var _editInputElement = require("./edit/editInputElement");
47
99
 
48
- Object.keys(_fireInputEvent).forEach(function (key) {
100
+ Object.keys(_editInputElement).forEach(function (key) {
49
101
  if (key === "default" || key === "__esModule") return;
50
- if (key in exports && exports[key] === _fireInputEvent[key]) return;
102
+ if (key in exports && exports[key] === _editInputElement[key]) return;
51
103
  Object.defineProperty(exports, key, {
52
104
  enumerable: true,
53
105
  get: function () {
54
- return _fireInputEvent[key];
106
+ return _editInputElement[key];
55
107
  }
56
108
  });
57
109
  });
@@ -147,6 +199,19 @@ Object.keys(_prepareInput).forEach(function (key) {
147
199
  });
148
200
  });
149
201
 
202
+ var _setFiles = require("./edit/setFiles");
203
+
204
+ Object.keys(_setFiles).forEach(function (key) {
205
+ if (key === "default" || key === "__esModule") return;
206
+ if (key in exports && exports[key] === _setFiles[key]) return;
207
+ Object.defineProperty(exports, key, {
208
+ enumerable: true,
209
+ get: function () {
210
+ return _setFiles[key];
211
+ }
212
+ });
213
+ });
214
+
150
215
  var _blur = require("./focus/blur");
151
216
 
152
217
  Object.keys(_blur).forEach(function (key) {
@@ -160,6 +225,19 @@ Object.keys(_blur).forEach(function (key) {
160
225
  });
161
226
  });
162
227
 
228
+ var _copySelection = require("./focus/copySelection");
229
+
230
+ Object.keys(_copySelection).forEach(function (key) {
231
+ if (key === "default" || key === "__esModule") return;
232
+ if (key in exports && exports[key] === _copySelection[key]) return;
233
+ Object.defineProperty(exports, key, {
234
+ enumerable: true,
235
+ get: function () {
236
+ return _copySelection[key];
237
+ }
238
+ });
239
+ });
240
+
163
241
  var _focus = require("./focus/focus");
164
242
 
165
243
  Object.keys(_focus).forEach(function (key) {
@@ -212,6 +290,19 @@ Object.keys(_isFocusable).forEach(function (key) {
212
290
  });
213
291
  });
214
292
 
293
+ var _selectAll = require("./focus/selectAll");
294
+
295
+ Object.keys(_selectAll).forEach(function (key) {
296
+ if (key === "default" || key === "__esModule") return;
297
+ if (key in exports && exports[key] === _selectAll[key]) return;
298
+ Object.defineProperty(exports, key, {
299
+ enumerable: true,
300
+ get: function () {
301
+ return _selectAll[key];
302
+ }
303
+ });
304
+ });
305
+
215
306
  var _selection = require("./focus/selection");
216
307
 
217
308
  Object.keys(_selection).forEach(function (key) {
@@ -277,6 +368,19 @@ Object.keys(_findClosest).forEach(function (key) {
277
368
  });
278
369
  });
279
370
 
371
+ var _getDocumentFromNode = require("./misc/getDocumentFromNode");
372
+
373
+ Object.keys(_getDocumentFromNode).forEach(function (key) {
374
+ if (key === "default" || key === "__esModule") return;
375
+ if (key in exports && exports[key] === _getDocumentFromNode[key]) return;
376
+ Object.defineProperty(exports, key, {
377
+ enumerable: true,
378
+ get: function () {
379
+ return _getDocumentFromNode[key];
380
+ }
381
+ });
382
+ });
383
+
280
384
  var _isDescendantOrSelf = require("./misc/isDescendantOrSelf");
281
385
 
282
386
  Object.keys(_isDescendantOrSelf).forEach(function (key) {
@@ -368,19 +472,6 @@ Object.keys(_hasFormSubmit).forEach(function (key) {
368
472
  });
369
473
  });
370
474
 
371
- var _fakeEvent = require("./pointer/fakeEvent");
372
-
373
- Object.keys(_fakeEvent).forEach(function (key) {
374
- if (key === "default" || key === "__esModule") return;
375
- if (key in exports && exports[key] === _fakeEvent[key]) return;
376
- Object.defineProperty(exports, key, {
377
- enumerable: true,
378
- get: function () {
379
- return _fakeEvent[key];
380
- }
381
- });
382
- });
383
-
384
475
  var _firePointerEvents = require("./pointer/firePointerEvents");
385
476
 
386
477
  Object.keys(_firePointerEvents).forEach(function (key) {
@@ -0,0 +1 @@
1
+ export declare function getDocumentFromNode(el: Node): Document | null;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getDocumentFromNode = getDocumentFromNode;
7
+
8
+ function getDocumentFromNode(el) {
9
+ return isDocument(el) ? el : el.ownerDocument;
10
+ }
11
+
12
+ function isDocument(node) {
13
+ return node.nodeType === 9;
14
+ }
@@ -13,11 +13,18 @@ function isVisible(element) {
13
13
  for (let el = element; (_el = el) != null && _el.ownerDocument; el = el.parentElement) {
14
14
  var _el;
15
15
 
16
- const display = window.getComputedStyle(el).display;
16
+ const {
17
+ display,
18
+ visibility
19
+ } = window.getComputedStyle(el);
17
20
 
18
21
  if (display === 'none') {
19
22
  return false;
20
23
  }
24
+
25
+ if (visibility === 'hidden') {
26
+ return false;
27
+ }
21
28
  }
22
29
 
23
30
  return true;
@@ -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.7",
3
+ "version": "14.0.0-beta.2",
4
4
  "description": "Fire events the same way the user does",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [
package/dist/clear.js DELETED
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.clear = clear;
7
-
8
- var _utils = require("./utils");
9
-
10
- function clear(element) {
11
- var _element$selectionSta, _element$selectionEnd;
12
-
13
- if (!(0, _utils.isElementType)(element, ['input', 'textarea'])) {
14
- // TODO: support contenteditable
15
- throw new Error('clear currently only supports input and textarea elements.');
16
- }
17
-
18
- if ((0, _utils.isDisabled)(element)) {
19
- return;
20
- } // TODO: track the selection range ourselves so we don't have to do this input "type" trickery
21
- // just like cypress does: https://github.com/cypress-io/cypress/blob/8d7f1a0bedc3c45a2ebf1ff50324b34129fdc683/packages/driver/src/dom/selection.ts#L16-L37
22
-
23
-
24
- const elementType = element.type;
25
-
26
- if (elementType !== 'textarea') {
27
- // setSelectionRange is not supported on certain types of inputs, e.g. "number" or "email"
28
- ;
29
- element.type = 'text';
30
- }
31
-
32
- this.type(element, '{selectall}{del}', {
33
- delay: 0,
34
- initialSelectionStart: (_element$selectionSta = element.selectionStart) != null ? _element$selectionSta :
35
- /* istanbul ignore next */
36
- undefined,
37
- initialSelectionEnd: (_element$selectionEnd = element.selectionEnd) != null ? _element$selectionEnd :
38
- /* istanbul ignore next */
39
- undefined
40
- });
41
-
42
- if (elementType !== 'textarea') {
43
- ;
44
- element.type = elementType;
45
- }
46
- }
package/dist/click.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { PointerOptions } from './utils';
2
- import type { UserEvent } from './setup';
3
- export declare interface clickOptions {
4
- skipHover?: boolean;
5
- clickCount?: number;
6
- }
7
- export declare function click(this: UserEvent, element: Element, init?: MouseEventInit, { skipHover, skipPointerEventsCheck, }?: clickOptions & PointerOptions): void;
8
- export declare function dblClick(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: clickOptions & PointerOptions): void;
9
- export declare function tripleClick(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: clickOptions & PointerOptions): void;
package/dist/click.js DELETED
@@ -1,62 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.click = click;
7
- exports.dblClick = dblClick;
8
- exports.tripleClick = tripleClick;
9
-
10
- var _utils = require("./utils");
11
-
12
- function click(element, init, {
13
- skipHover = false,
14
- skipPointerEventsCheck = false
15
- } = {}) {
16
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
17
- throw new Error('unable to click element as it has or inherits pointer-events set to "none".');
18
- } // istanbul ignore else
19
-
20
-
21
- if (!skipHover) // We just checked for `pointerEvents`. We can always skip this one in `hover`.
22
- this.hover(element, init, {
23
- skipPointerEventsCheck: true
24
- });
25
- const keys = (init == null ? void 0 : init.button) === 2 || (init == null ? void 0 : init.buttons) === 2 ? '[MouseRight]' : '[MouseLeft]';
26
- this.pointer({
27
- keys,
28
- target: element
29
- });
30
- }
31
-
32
- function dblClick(element, init, {
33
- skipPointerEventsCheck = false
34
- } = {}) {
35
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
36
- throw new Error('unable to double-click element as it has or inherits pointer-events set to "none".');
37
- }
38
-
39
- this.hover(element, init, {
40
- skipPointerEventsCheck
41
- });
42
- this.pointer({
43
- keys: '[MouseLeft][MouseLeft]',
44
- target: element
45
- });
46
- }
47
-
48
- function tripleClick(element, init, {
49
- skipPointerEventsCheck = false
50
- } = {}) {
51
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
52
- throw new Error('unable to triple-click element as it has or inherits pointer-events set to "none".');
53
- }
54
-
55
- this.hover(element, init, {
56
- skipPointerEventsCheck: true
57
- });
58
- this.pointer({
59
- keys: '[MouseLeft][MouseLeft][MouseLeft]',
60
- target: element
61
- });
62
- }
package/dist/hover.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- import { PointerOptions } from './utils';
3
- export declare function hover(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: PointerOptions): void;
4
- export declare function unhover(this: UserEvent, element: Element, init?: MouseEventInit, { skipPointerEventsCheck }?: PointerOptions): void;
package/dist/hover.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.hover = hover;
7
- exports.unhover = unhover;
8
-
9
- var _pointer = require("./pointer");
10
-
11
- var _utils = require("./utils");
12
-
13
- function hover(element, init, {
14
- skipPointerEventsCheck = false
15
- } = {}) {
16
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
17
- throw new Error('unable to hover element as it has or inherits pointer-events set to "none".');
18
- }
19
-
20
- const pointerState = (0, _pointer.createPointerState)();
21
- pointerState.position.mouse.target = element.ownerDocument.body;
22
- this.pointer({
23
- target: element
24
- }, {
25
- pointerState
26
- });
27
- }
28
-
29
- function unhover(element, init, {
30
- skipPointerEventsCheck = false
31
- } = {}) {
32
- if (!skipPointerEventsCheck && !(0, _utils.hasPointerEvents)(element)) {
33
- throw new Error('unable to unhover element as it has or inherits pointer-events set to "none".');
34
- }
35
-
36
- const pointerState = (0, _pointer.createPointerState)();
37
- pointerState.position.mouse.target = element;
38
- this.pointer({
39
- target: element.ownerDocument.body
40
- }, {
41
- pointerState
42
- });
43
- }