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

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 (120) 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.js +3 -1
  30. package/dist/keyboard/plugins/functional.js +38 -20
  31. package/dist/keyboard/plugins/index.d.ts +0 -1
  32. package/dist/keyboard/plugins/index.js +1 -10
  33. package/dist/keyboard/types.d.ts +3 -19
  34. package/dist/options.d.ts +102 -0
  35. package/dist/options.js +36 -0
  36. package/dist/pointer/index.d.ts +6 -14
  37. package/dist/pointer/index.js +8 -42
  38. package/dist/pointer/parseKeyDef.d.ts +2 -2
  39. package/dist/pointer/parseKeyDef.js +1 -3
  40. package/dist/pointer/pointerAction.d.ts +3 -2
  41. package/dist/pointer/pointerAction.js +9 -15
  42. package/dist/pointer/pointerMove.d.ts +2 -1
  43. package/dist/pointer/pointerPress.d.ts +2 -1
  44. package/dist/pointer/pointerPress.js +13 -16
  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/getTabDestination.js +14 -1
  87. package/dist/utils/focus/selectAll.d.ts +1 -0
  88. package/dist/utils/focus/selectAll.js +13 -0
  89. package/dist/utils/index.d.ts +8 -2
  90. package/dist/utils/index.js +95 -17
  91. package/dist/utils/misc/getDocumentFromNode.d.ts +1 -0
  92. package/dist/utils/misc/getDocumentFromNode.js +14 -0
  93. package/dist/utils/misc/hasFormSubmit.js +1 -1
  94. package/dist/utils/misc/isVisible.js +8 -1
  95. package/dist/utils/pointer/firePointerEvents.d.ts +12 -1
  96. package/dist/utils/pointer/firePointerEvents.js +67 -12
  97. package/package.json +1 -1
  98. package/dist/clear.js +0 -46
  99. package/dist/click.d.ts +0 -9
  100. package/dist/click.js +0 -62
  101. package/dist/hover.d.ts +0 -4
  102. package/dist/hover.js +0 -43
  103. package/dist/keyboard/getNextKeyDef.js +0 -85
  104. package/dist/keyboard/keyboardImplementation.d.ts +0 -3
  105. package/dist/keyboard/keyboardImplementation.js +0 -169
  106. package/dist/keyboard/specialCharMap.d.ts +0 -22
  107. package/dist/keyboard/specialCharMap.js +0 -30
  108. package/dist/paste.d.ts +0 -7
  109. package/dist/paste.js +0 -60
  110. package/dist/selectOptions.d.ts +0 -4
  111. package/dist/setup.d.ts +0 -92
  112. package/dist/setup.js +0 -203
  113. package/dist/tab.d.ts +0 -5
  114. package/dist/tab.js +0 -12
  115. package/dist/type.d.ts +0 -14
  116. package/dist/type.js +0 -74
  117. package/dist/upload.d.ts +0 -10
  118. package/dist/utils/edit/fireInputEvent.d.ts +0 -11
  119. package/dist/utils/pointer/fakeEvent.d.ts +0 -20
  120. 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
+ }
@@ -21,7 +21,20 @@ function getTabDestination(activeElement, shift) {
21
21
 
22
22
  if (activeElement.getAttribute('tabindex') !== '-1') {
23
23
  // tabindex has no effect if the active element has tabindex="-1"
24
- enabledElements.sort((a, b) => Number(a.getAttribute('tabindex')) - Number(b.getAttribute('tabindex')));
24
+ enabledElements.sort((a, b) => {
25
+ const i = Number(a.getAttribute('tabindex'));
26
+ const j = Number(b.getAttribute('tabindex'));
27
+
28
+ if (i === j) {
29
+ return 0;
30
+ } else if (i === 0) {
31
+ return 1;
32
+ } else if (j === 0) {
33
+ return -1;
34
+ }
35
+
36
+ return i - j;
37
+ });
25
38
  }
26
39
 
27
40
  const checkedRadio = {};
@@ -2,3 +2,4 @@
2
2
  * Expand a selection like the browser does when pressing Ctrl+A.
3
3
  */
4
4
  export declare function selectAll(target: Element): void;
5
+ export declare function isAllSelected(target: Element): boolean;
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.isAllSelected = isAllSelected;
6
7
  exports.selectAll = selectAll;
7
8
 
8
9
  var _document = require("../../document");
@@ -35,4 +36,16 @@ function selectAll(target) {
35
36
  anchorOffset: 0,
36
37
  focusOffset: focusNode.childNodes.length
37
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;
38
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,7 +13,9 @@ 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';
@@ -20,6 +26,7 @@ export * from './focus/selector';
20
26
  export * from './keyDef/readNextDescriptor';
21
27
  export * from './misc/eventWrapper';
22
28
  export * from './misc/findClosest';
29
+ export * from './misc/getDocumentFromNode';
23
30
  export * from './misc/isDescendantOrSelf';
24
31
  export * from './misc/isElementType';
25
32
  export * from './misc/isVisible';
@@ -27,6 +34,5 @@ export * from './misc/isDisabled';
27
34
  export * from './misc/wait';
28
35
  export * from './misc/hasPointerEvents';
29
36
  export * from './misc/hasFormSubmit';
30
- export * from './pointer/fakeEvent';
31
37
  export * from './pointer/firePointerEvents';
32
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) {
@@ -290,6 +368,19 @@ Object.keys(_findClosest).forEach(function (key) {
290
368
  });
291
369
  });
292
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
+
293
384
  var _isDescendantOrSelf = require("./misc/isDescendantOrSelf");
294
385
 
295
386
  Object.keys(_isDescendantOrSelf).forEach(function (key) {
@@ -381,19 +472,6 @@ Object.keys(_hasFormSubmit).forEach(function (key) {
381
472
  });
382
473
  });
383
474
 
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
475
  var _firePointerEvents = require("./pointer/firePointerEvents");
398
476
 
399
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
+ }
@@ -5,6 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.hasFormSubmit = void 0;
7
7
 
8
- const hasFormSubmit = form => !!(form && (form.querySelector('input[type="submit"]') || form.querySelector('button[type="submit"]')));
8
+ const hasFormSubmit = form => !!(form != null && form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]'));
9
9
 
10
10
  exports.hasFormSubmit = hasFormSubmit;
@@ -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
  }
@@ -38,18 +37,74 @@ function firePointerEvent(target, type, {
38
37
  init.isPrimary = isPrimary;
39
38
  }
40
39
 
41
- if (['mousedown', 'mouseup', 'pointerdown', 'pointerup', 'click'].includes(type)) {
42
- init.button = (0, _mouseButtons.getMouseButton)(button != null ? button : 0);
43
- init.buttons = (0, _mouseButtons.getMouseButtons)(...pointerState.pressed.filter(p => p.keyDef.pointerType === pointerType).map(p => {
44
- var _p$keyDef$button;
40
+ init.button = (0, _mouseButtons.getMouseButton)(button != null ? button : 0);
41
+ init.buttons = (0, _mouseButtons.getMouseButtons)(...pointerState.pressed.filter(p => p.keyDef.pointerType === pointerType).map(p => {
42
+ var _p$keyDef$button;
45
43
 
46
- return (_p$keyDef$button = p.keyDef.button) != null ? _p$keyDef$button : 0;
47
- }));
48
- }
44
+ return (_p$keyDef$button = p.keyDef.button) != null ? _p$keyDef$button : 0;
45
+ }));
49
46
 
50
- if (['mousedown', 'mouseup', 'click'].includes(type)) {
47
+ if (['mousedown', 'mouseup', 'click', 'dblclick', 'contextmenu'].includes(type)) {
51
48
  init.detail = clickCount;
52
49
  }
53
50
 
54
- return (0, _dom.fireEvent)(target, new Event(type, init));
51
+ const eventKey = Object.keys(_eventMap.eventMap).find(k => k.toLowerCase() === type);
52
+
53
+ const event = _dom.createEvent[eventKey](target, init); // see https://github.com/testing-library/react-testing-library/issues/268
54
+
55
+
56
+ assignPositionInit(event, init);
57
+ assignPointerInit(event, init);
58
+ return (0, _dom.fireEvent)(target, event);
59
+ }
60
+
61
+ function assignProps(obj, props) {
62
+ for (const [key, value] of Object.entries(props)) {
63
+ Object.defineProperty(obj, key, {
64
+ get: () => value
65
+ });
66
+ }
67
+ }
68
+
69
+ function assignPositionInit(obj, {
70
+ x,
71
+ y,
72
+ clientX,
73
+ clientY,
74
+ offsetX,
75
+ offsetY,
76
+ pageX,
77
+ pageY,
78
+ screenX,
79
+ screenY
80
+ }) {
81
+ var _ref, _ref2, _ref3, _ref4;
82
+
83
+ assignProps(obj, {
84
+ /* istanbul ignore start */
85
+ x: (_ref = x != null ? x : clientX) != null ? _ref : 0,
86
+ y: (_ref2 = y != null ? y : clientY) != null ? _ref2 : 0,
87
+ clientX: (_ref3 = x != null ? x : clientX) != null ? _ref3 : 0,
88
+ clientY: (_ref4 = y != null ? y : clientY) != null ? _ref4 : 0,
89
+ offsetX: offsetX != null ? offsetX : 0,
90
+ offsetY: offsetY != null ? offsetY : 0,
91
+ pageX: pageX != null ? pageX : 0,
92
+ pageY: pageY != null ? pageY : 0,
93
+ screenX: screenX != null ? screenX : 0,
94
+ screenY: screenY != null ? screenY : 0
95
+ /* istanbul ignore end */
96
+
97
+ });
98
+ }
99
+
100
+ function assignPointerInit(obj, {
101
+ isPrimary,
102
+ pointerId,
103
+ pointerType
104
+ }) {
105
+ assignProps(obj, {
106
+ isPrimary,
107
+ pointerId,
108
+ pointerType
109
+ });
55
110
  }
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-beta.3",
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
- }