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

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 (203) hide show
  1. package/README.md +5 -192
  2. package/dist/index.cjs +2864 -0
  3. package/dist/index.mjs +2935 -0
  4. package/dist/types/clipboard/copy.d.ts +2 -0
  5. package/dist/types/clipboard/cut.d.ts +2 -0
  6. package/dist/types/clipboard/index.d.ts +3 -0
  7. package/dist/types/clipboard/paste.d.ts +2 -0
  8. package/dist/types/convenience/click.d.ts +4 -0
  9. package/dist/types/convenience/hover.d.ts +3 -0
  10. package/dist/types/convenience/index.d.ts +3 -0
  11. package/dist/types/convenience/tab.d.ts +4 -0
  12. package/dist/{document → types/document}/index.d.ts +0 -0
  13. package/dist/{document → types/document}/interceptor.d.ts +0 -0
  14. package/dist/{document → types/document}/selection.d.ts +0 -0
  15. package/dist/{document → types/document}/value.d.ts +0 -0
  16. package/dist/types/event/behavior/click.d.ts +1 -0
  17. package/dist/types/event/behavior/index.d.ts +6 -0
  18. package/dist/types/event/behavior/keydown.d.ts +1 -0
  19. package/dist/types/event/behavior/keypress.d.ts +1 -0
  20. package/dist/types/event/behavior/keyup.d.ts +1 -0
  21. package/dist/types/event/behavior/registry.d.ts +9 -0
  22. package/dist/types/event/createEvent.d.ts +8 -0
  23. package/dist/types/event/dispatchEvent.d.ts +2 -0
  24. package/dist/types/event/eventMap.d.ts +342 -0
  25. package/dist/types/event/eventTypes.d.ts +2 -0
  26. package/dist/types/event/index.d.ts +6 -0
  27. package/dist/types/event/types.d.ts +13 -0
  28. package/dist/types/event/wrapEvent.d.ts +1 -0
  29. package/dist/types/index.d.ts +4 -0
  30. package/dist/types/keyboard/index.d.ts +7 -0
  31. package/dist/{keyboard → types/keyboard}/keyMap.d.ts +0 -0
  32. package/dist/types/keyboard/keyboardAction.d.ts +10 -0
  33. package/dist/types/keyboard/modifiers.d.ts +9 -0
  34. package/dist/{keyboard/getNextKeyDef.d.ts → types/keyboard/parseKeyDef.d.ts} +4 -6
  35. package/dist/{keyboard → types/keyboard}/types.d.ts +19 -26
  36. package/dist/types/options.d.ts +117 -0
  37. package/dist/types/pointer/firePointerEvents.d.ts +11 -0
  38. package/dist/types/pointer/index.d.ts +10 -0
  39. package/dist/{pointer → types/pointer}/keyMap.d.ts +0 -0
  40. package/dist/types/pointer/parseKeyDef.d.ts +6 -0
  41. package/dist/{pointer → types/pointer}/pointerAction.d.ts +3 -2
  42. package/dist/types/pointer/pointerMove.d.ts +6 -0
  43. package/dist/types/pointer/pointerPress.d.ts +8 -0
  44. package/dist/{pointer → types/pointer}/resolveSelectionTarget.d.ts +0 -0
  45. package/dist/{pointer → types/pointer}/types.d.ts +2 -12
  46. package/dist/types/setup/api.d.ts +5 -0
  47. package/dist/types/setup/config.d.ts +10 -0
  48. package/dist/types/setup/directApi.d.ts +19 -0
  49. package/dist/types/setup/index.d.ts +36 -0
  50. package/dist/types/setup/setup.d.ts +20 -0
  51. package/dist/types/setup/wrapAsync.d.ts +4 -0
  52. package/dist/types/utility/clear.d.ts +2 -0
  53. package/dist/types/utility/index.d.ts +4 -0
  54. package/dist/types/utility/selectOptions.d.ts +3 -0
  55. package/dist/types/utility/type.d.ts +9 -0
  56. package/dist/types/utility/upload.d.ts +5 -0
  57. package/dist/{utils → types/utils}/click/isClickableInput.d.ts +0 -0
  58. package/dist/types/utils/dataTransfer/Blob.d.ts +1 -0
  59. package/dist/types/utils/dataTransfer/Clipboard.d.ts +9 -0
  60. package/dist/types/utils/dataTransfer/DataTransfer.d.ts +2 -0
  61. package/dist/types/utils/dataTransfer/FileList.d.ts +1 -0
  62. package/dist/{utils → types/utils}/edit/buildTimeValue.d.ts +0 -0
  63. package/dist/{utils → types/utils}/edit/getValue.d.ts +0 -0
  64. package/dist/types/utils/edit/input.d.ts +2 -0
  65. package/dist/{utils → types/utils}/edit/isContentEditable.d.ts +0 -0
  66. package/dist/{utils → types/utils}/edit/isEditable.d.ts +0 -0
  67. package/dist/types/utils/edit/isValidDateOrTimeValue.d.ts +3 -0
  68. package/dist/{utils → types/utils}/edit/maxLength.d.ts +0 -0
  69. package/dist/types/utils/edit/setFiles.d.ts +12 -0
  70. package/dist/{utils → types/utils}/focus/blur.d.ts +0 -0
  71. package/dist/types/utils/focus/copySelection.d.ts +1 -0
  72. package/dist/types/utils/focus/cursor.d.ts +9 -0
  73. package/dist/{utils → types/utils}/focus/focus.d.ts +3 -0
  74. package/dist/{utils → types/utils}/focus/getActiveElement.d.ts +0 -0
  75. package/dist/{utils → types/utils}/focus/getTabDestination.d.ts +0 -0
  76. package/dist/{utils → types/utils}/focus/isFocusable.d.ts +0 -0
  77. package/dist/{utils → types/utils}/focus/selectAll.d.ts +1 -0
  78. package/dist/{utils → types/utils}/focus/selection.d.ts +4 -0
  79. package/dist/{utils → types/utils}/focus/selector.d.ts +0 -0
  80. package/dist/{utils → types/utils}/index.d.ts +14 -11
  81. package/dist/{utils → types/utils}/keyDef/readNextDescriptor.d.ts +0 -0
  82. package/dist/types/utils/keyboard/getKeyEventProps.d.ts +5 -0
  83. package/dist/types/utils/keyboard/getUIEventModifiers.d.ts +15 -0
  84. package/dist/types/utils/misc/cloneEvent.d.ts +1 -0
  85. package/dist/{utils → types/utils}/misc/eventWrapper.d.ts +0 -0
  86. package/dist/types/utils/misc/findClosest.d.ts +1 -0
  87. package/dist/types/utils/misc/getDocumentFromNode.d.ts +1 -0
  88. package/dist/{utils → types/utils}/misc/isDescendantOrSelf.d.ts +0 -0
  89. package/dist/{utils → types/utils}/misc/isDisabled.d.ts +0 -0
  90. package/dist/{utils → types/utils}/misc/isElementType.d.ts +0 -0
  91. package/dist/{utils → types/utils}/misc/isVisible.d.ts +0 -0
  92. package/dist/types/utils/misc/level.d.ts +17 -0
  93. package/dist/{utils → types/utils}/misc/wait.d.ts +0 -0
  94. package/dist/types/utils/pointer/cssPointerEvents.d.ts +15 -0
  95. package/dist/{utils → types/utils}/pointer/mouseButtons.d.ts +0 -0
  96. package/package.json +13 -30
  97. package/CHANGELOG.md +0 -5
  98. package/dist/clear.d.ts +0 -2
  99. package/dist/clear.js +0 -46
  100. package/dist/click.d.ts +0 -9
  101. package/dist/click.js +0 -62
  102. package/dist/document/index.js +0 -100
  103. package/dist/document/interceptor.js +0 -37
  104. package/dist/document/selection.js +0 -90
  105. package/dist/document/value.js +0 -77
  106. package/dist/hover.d.ts +0 -4
  107. package/dist/hover.js +0 -43
  108. package/dist/index.d.ts +0 -8
  109. package/dist/index.js +0 -22
  110. package/dist/keyboard/getEventProps.d.ts +0 -17
  111. package/dist/keyboard/getEventProps.js +0 -33
  112. package/dist/keyboard/getNextKeyDef.js +0 -85
  113. package/dist/keyboard/index.d.ts +0 -19
  114. package/dist/keyboard/index.js +0 -78
  115. package/dist/keyboard/keyMap.js +0 -143
  116. package/dist/keyboard/keyboardImplementation.d.ts +0 -3
  117. package/dist/keyboard/keyboardImplementation.js +0 -169
  118. package/dist/keyboard/plugins/arrow.d.ts +0 -6
  119. package/dist/keyboard/plugins/arrow.js +0 -28
  120. package/dist/keyboard/plugins/character.d.ts +0 -5
  121. package/dist/keyboard/plugins/character.js +0 -166
  122. package/dist/keyboard/plugins/combination.d.ts +0 -5
  123. package/dist/keyboard/plugins/combination.js +0 -17
  124. package/dist/keyboard/plugins/control.d.ts +0 -6
  125. package/dist/keyboard/plugins/control.js +0 -52
  126. package/dist/keyboard/plugins/functional.d.ts +0 -11
  127. package/dist/keyboard/plugins/functional.js +0 -140
  128. package/dist/keyboard/plugins/index.d.ts +0 -8
  129. package/dist/keyboard/plugins/index.js +0 -42
  130. package/dist/keyboard/shared/fireChangeForInputTimeIfValid.d.ts +0 -3
  131. package/dist/keyboard/shared/fireChangeForInputTimeIfValid.js +0 -20
  132. package/dist/keyboard/shared/index.d.ts +0 -1
  133. package/dist/keyboard/shared/index.js +0 -18
  134. package/dist/keyboard/specialCharMap.d.ts +0 -22
  135. package/dist/keyboard/specialCharMap.js +0 -30
  136. package/dist/keyboard/types.js +0 -19
  137. package/dist/paste.d.ts +0 -7
  138. package/dist/paste.js +0 -60
  139. package/dist/pointer/index.d.ts +0 -18
  140. package/dist/pointer/index.js +0 -90
  141. package/dist/pointer/keyMap.js +0 -29
  142. package/dist/pointer/parseKeyDef.d.ts +0 -6
  143. package/dist/pointer/parseKeyDef.js +0 -36
  144. package/dist/pointer/pointerAction.js +0 -52
  145. package/dist/pointer/pointerMove.d.ts +0 -5
  146. package/dist/pointer/pointerMove.js +0 -136
  147. package/dist/pointer/pointerPress.d.ts +0 -7
  148. package/dist/pointer/pointerPress.js +0 -330
  149. package/dist/pointer/resolveSelectionTarget.js +0 -75
  150. package/dist/pointer/types.js +0 -1
  151. package/dist/selectOptions.d.ts +0 -4
  152. package/dist/selectOptions.js +0 -142
  153. package/dist/setup.d.ts +0 -92
  154. package/dist/setup.js +0 -203
  155. package/dist/tab.d.ts +0 -5
  156. package/dist/tab.js +0 -12
  157. package/dist/type.d.ts +0 -14
  158. package/dist/type.js +0 -74
  159. package/dist/upload.d.ts +0 -10
  160. package/dist/upload.js +0 -92
  161. package/dist/utils/click/isClickableInput.js +0 -14
  162. package/dist/utils/edit/buildTimeValue.js +0 -44
  163. package/dist/utils/edit/calculateNewValue.d.ts +0 -16
  164. package/dist/utils/edit/calculateNewValue.js +0 -50
  165. package/dist/utils/edit/fireInputEvent.d.ts +0 -11
  166. package/dist/utils/edit/fireInputEvent.js +0 -65
  167. package/dist/utils/edit/getValue.js +0 -23
  168. package/dist/utils/edit/isContentEditable.js +0 -25
  169. package/dist/utils/edit/isEditable.js +0 -42
  170. package/dist/utils/edit/isValidDateValue.d.ts +0 -3
  171. package/dist/utils/edit/isValidDateValue.js +0 -12
  172. package/dist/utils/edit/isValidInputTimeValue.d.ts +0 -3
  173. package/dist/utils/edit/isValidInputTimeValue.js +0 -12
  174. package/dist/utils/edit/maxLength.js +0 -50
  175. package/dist/utils/edit/prepareInput.d.ts +0 -4
  176. package/dist/utils/edit/prepareInput.js +0 -60
  177. package/dist/utils/focus/blur.js +0 -19
  178. package/dist/utils/focus/focus.js +0 -22
  179. package/dist/utils/focus/getActiveElement.js +0 -26
  180. package/dist/utils/focus/getTabDestination.js +0 -71
  181. package/dist/utils/focus/isFocusable.js +0 -12
  182. package/dist/utils/focus/selectAll.js +0 -38
  183. package/dist/utils/focus/selection.js +0 -190
  184. package/dist/utils/focus/selector.js +0 -8
  185. package/dist/utils/index.js +0 -421
  186. package/dist/utils/keyDef/readNextDescriptor.js +0 -102
  187. package/dist/utils/misc/eventWrapper.js +0 -16
  188. package/dist/utils/misc/findClosest.d.ts +0 -1
  189. package/dist/utils/misc/findClosest.js +0 -20
  190. package/dist/utils/misc/hasFormSubmit.d.ts +0 -1
  191. package/dist/utils/misc/hasFormSubmit.js +0 -10
  192. package/dist/utils/misc/hasPointerEvents.d.ts +0 -15
  193. package/dist/utils/misc/hasPointerEvents.js +0 -24
  194. package/dist/utils/misc/isDescendantOrSelf.js +0 -20
  195. package/dist/utils/misc/isDisabled.js +0 -12
  196. package/dist/utils/misc/isElementType.js +0 -24
  197. package/dist/utils/misc/isVisible.js +0 -24
  198. package/dist/utils/misc/wait.js +0 -10
  199. package/dist/utils/pointer/fakeEvent.d.ts +0 -20
  200. package/dist/utils/pointer/fakeEvent.js +0 -91
  201. package/dist/utils/pointer/firePointerEvents.d.ts +0 -14
  202. package/dist/utils/pointer/firePointerEvents.js +0 -55
  203. package/dist/utils/pointer/mouseButtons.js +0 -45
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.0.0-alpha.8",
3
+ "version": "14.0.0-beta.11",
4
4
  "description": "Fire events the same way the user does",
5
- "main": "dist/index.js",
6
5
  "keywords": [
7
6
  "react-testing-library",
8
7
  "dom-testing-library",
@@ -26,8 +25,17 @@
26
25
  "files": [
27
26
  "dist"
28
27
  ],
28
+ "main": "./dist/index.cjs",
29
+ "module": "./dist/index.mjs",
30
+ "exports": {
31
+ ".": {
32
+ "require": "./dist/index.cjs",
33
+ "default": "./dist/index.mjs"
34
+ }
35
+ },
36
+ "types": "./dist/types/index.d.ts",
29
37
  "scripts": {
30
- "build": "kcd-scripts build --no-ts-defs && tsc -p tsconfig.build.json",
38
+ "build": "node build.js",
31
39
  "lint": "kcd-scripts lint",
32
40
  "setup": "npm install && npm run validate -s",
33
41
  "test": "kcd-scripts test",
@@ -46,6 +54,7 @@
46
54
  "@types/estree": "0.0.45",
47
55
  "@types/jest-in-case": "^1.0.3",
48
56
  "@types/react": "^17.0.3",
57
+ "esbuild": "^0.14.9",
49
58
  "eslint-import-resolver-typescript": "^2.5.0",
50
59
  "is-ci": "^2.0.0",
51
60
  "jest-in-case": "^1.0.2",
@@ -57,31 +66,5 @@
57
66
  },
58
67
  "peerDependencies": {
59
68
  "@testing-library/dom": ">=7.21.4"
60
- },
61
- "eslintConfig": {
62
- "extends": "./node_modules/kcd-scripts/eslint.js",
63
- "rules": {
64
- "jsx-a11y/click-events-have-key-events": "off",
65
- "jsx-a11y/tabindex-no-positive": "off",
66
- "no-func-assign": "off",
67
- "no-return-assign": "off",
68
- "react/prop-types": "off",
69
- "testing-library/no-dom-import": "off"
70
- },
71
- "overrides": [
72
- {
73
- "files": [
74
- "**/__tests__/**"
75
- ],
76
- "rules": {
77
- "no-console": "off"
78
- }
79
- }
80
- ]
81
- },
82
- "eslintIgnore": [
83
- "node_modules",
84
- "coverage",
85
- "dist"
86
- ]
69
+ }
87
70
  }
package/CHANGELOG.md DELETED
@@ -1,5 +0,0 @@
1
- # CHANGELOG
2
-
3
- The changelog is automatically updated using
4
- [semantic-release](https://github.com/semantic-release/semantic-release). You
5
- can see it on the [releases page](../../releases).
package/dist/clear.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- export declare function clear(this: UserEvent, element: Element): void;
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
- }
@@ -1,100 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "endTrackValue", {
7
- enumerable: true,
8
- get: function () {
9
- return _value.endTrackValue;
10
- }
11
- });
12
- Object.defineProperty(exports, "getUISelection", {
13
- enumerable: true,
14
- get: function () {
15
- return _selection.getUISelection;
16
- }
17
- });
18
- Object.defineProperty(exports, "getUIValue", {
19
- enumerable: true,
20
- get: function () {
21
- return _value.getUIValue;
22
- }
23
- });
24
- exports.prepareDocument = prepareDocument;
25
- Object.defineProperty(exports, "setUISelection", {
26
- enumerable: true,
27
- get: function () {
28
- return _selection.setUISelection;
29
- }
30
- });
31
- Object.defineProperty(exports, "setUIValue", {
32
- enumerable: true,
33
- get: function () {
34
- return _value.setUIValue;
35
- }
36
- });
37
- Object.defineProperty(exports, "startTrackValue", {
38
- enumerable: true,
39
- get: function () {
40
- return _value.startTrackValue;
41
- }
42
- });
43
-
44
- var _dom = require("@testing-library/dom");
45
-
46
- var _selection = require("./selection");
47
-
48
- var _value = require("./value");
49
-
50
- const isPrepared = Symbol('Node prepared with document state workarounds');
51
-
52
- function prepareDocument(document) {
53
- if (document[isPrepared]) {
54
- return;
55
- }
56
-
57
- document.addEventListener('focus', e => {
58
- const el = e.target;
59
- prepareElement(el);
60
- }, {
61
- capture: true,
62
- passive: true
63
- }); // Our test environment defaults to `document.body` as `activeElement`.
64
- // In other environments this might be `null` when preparing.
65
- // istanbul ignore else
66
-
67
- if (document.activeElement) {
68
- prepareElement(document.activeElement);
69
- }
70
-
71
- document.addEventListener('blur', e => {
72
- const el = e.target;
73
- const initialValue = (0, _value.getInitialValue)(el);
74
-
75
- if (typeof initialValue === 'string' && el.value !== initialValue) {
76
- _dom.fireEvent.change(el);
77
- }
78
- }, {
79
- capture: true,
80
- passive: true
81
- });
82
- document[isPrepared] = isPrepared;
83
- }
84
-
85
- function prepareElement(el) {
86
- if ('value' in el) {
87
- (0, _value.setInitialValue)(el);
88
- }
89
-
90
- if (el[isPrepared]) {
91
- return;
92
- }
93
-
94
- if ('value' in el) {
95
- (0, _value.prepareValueInterceptor)(el);
96
- (0, _selection.prepareSelectionInterceptor)(el);
97
- }
98
-
99
- el[isPrepared] = isPrepared;
100
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.prepareInterceptor = prepareInterceptor;
7
- const Interceptor = Symbol('Interceptor for programmatical calls');
8
-
9
- function prepareInterceptor(element, propName, interceptorImpl) {
10
- const prototypeDescriptor = Object.getOwnPropertyDescriptor(element.constructor.prototype, propName);
11
- const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
12
- const target = prototypeDescriptor != null && prototypeDescriptor.set ? 'set' : 'value';
13
-
14
- if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== 'function' || prototypeDescriptor[target][Interceptor]) {
15
- return;
16
- }
17
-
18
- function intercept(...args) {
19
- const {
20
- applyNative = true,
21
- realArgs
22
- } = interceptorImpl.call(this, ...args);
23
- const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
24
-
25
- if (target === 'set') {
26
- realFunc.call(this, realArgs);
27
- } else {
28
- realFunc.call(this, ...realArgs);
29
- }
30
- }
31
-
32
- ;
33
- intercept[Interceptor] = Interceptor;
34
- Object.defineProperty(element, propName, { ...(objectDescriptor != null ? objectDescriptor : prototypeDescriptor),
35
- [target]: intercept
36
- });
37
- }
@@ -1,90 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.clearUISelection = clearUISelection;
7
- exports.getUISelection = getUISelection;
8
- exports.prepareSelectionInterceptor = prepareSelectionInterceptor;
9
- exports.setUISelection = setUISelection;
10
-
11
- var _ = require(".");
12
-
13
- var _interceptor = require("./interceptor");
14
-
15
- const UISelection = Symbol('Displayed selection in UI');
16
-
17
- function prepareSelectionInterceptor(element) {
18
- (0, _interceptor.prepareInterceptor)(element, 'setSelectionRange', function interceptorImpl(start, end, direction = 'none') {
19
- const isUI = start && typeof start === 'object' && start[UISelection];
20
-
21
- if (!isUI) {
22
- this[UISelection] = undefined;
23
- }
24
-
25
- return {
26
- realArgs: [Number(start), end, direction]
27
- };
28
- });
29
- (0, _interceptor.prepareInterceptor)(element, 'selectionStart', function interceptorImpl(v) {
30
- this[UISelection] = undefined;
31
- return {
32
- realArgs: v
33
- };
34
- });
35
- (0, _interceptor.prepareInterceptor)(element, 'selectionEnd', function interceptorImpl(v) {
36
- this[UISelection] = undefined;
37
- return {
38
- realArgs: v
39
- };
40
- });
41
- }
42
-
43
- function setUISelection(element, {
44
- focusOffset: focusOffsetParam,
45
- anchorOffset: anchorOffsetParam = focusOffsetParam
46
- }, mode = 'replace') {
47
- const valueLength = (0, _.getUIValue)(element).length;
48
-
49
- const sanitizeOffset = o => Math.max(0, Math.min(valueLength, o));
50
-
51
- const anchorOffset = mode === 'replace' || element[UISelection] === undefined ? sanitizeOffset(anchorOffsetParam) : element[UISelection].anchorOffset;
52
- const focusOffset = sanitizeOffset(focusOffsetParam);
53
- const startOffset = Math.min(anchorOffset, focusOffset);
54
- const endOffset = Math.max(anchorOffset, focusOffset);
55
- element[UISelection] = {
56
- anchorOffset,
57
- focusOffset
58
- };
59
-
60
- if (element.selectionStart === startOffset && element.selectionEnd === endOffset) {
61
- return;
62
- } // eslint-disable-next-line no-new-wrappers
63
-
64
-
65
- const startObj = new Number(startOffset);
66
- startObj[UISelection] = UISelection;
67
-
68
- try {
69
- element.setSelectionRange(startObj, endOffset);
70
- } catch {// DOMException for invalid state is expected when calling this
71
- // on an element without support for setSelectionRange
72
- }
73
- }
74
-
75
- function getUISelection(element) {
76
- var _element$UISelection, _element$selectionSta, _element$selectionEnd;
77
-
78
- const sel = (_element$UISelection = element[UISelection]) != null ? _element$UISelection : {
79
- anchorOffset: (_element$selectionSta = element.selectionStart) != null ? _element$selectionSta : 0,
80
- focusOffset: (_element$selectionEnd = element.selectionEnd) != null ? _element$selectionEnd : 0
81
- };
82
- return { ...sel,
83
- startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
84
- endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
85
- };
86
- }
87
-
88
- function clearUISelection(element) {
89
- element[UISelection] = undefined;
90
- }
@@ -1,77 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.endTrackValue = endTrackValue;
7
- exports.getInitialValue = getInitialValue;
8
- exports.getUIValue = getUIValue;
9
- exports.prepareValueInterceptor = prepareValueInterceptor;
10
- exports.setInitialValue = setInitialValue;
11
- exports.setUIValue = setUIValue;
12
- exports.startTrackValue = startTrackValue;
13
-
14
- var _interceptor = require("./interceptor");
15
-
16
- var _selection = require("./selection");
17
-
18
- const UIValue = Symbol('Displayed value in UI');
19
- const InitialValue = Symbol('Initial value to compare on blur');
20
- const TrackChanges = Symbol('Track programmatic changes for React workaround');
21
-
22
- function valueInterceptor(v) {
23
- const isUI = typeof v === 'object' && v[UIValue];
24
- this[UIValue] = isUI ? String(v) : undefined;
25
-
26
- if (!isUI) {
27
- trackValue(this, String(v));
28
- this[InitialValue] = String(v); // Programmatically setting the value property
29
- // moves the cursor to the end of the input.
30
-
31
- (0, _selection.clearUISelection)(this);
32
- }
33
-
34
- return {
35
- applyNative: !!isUI,
36
- realArgs: String(v)
37
- };
38
- }
39
-
40
- function prepareValueInterceptor(element) {
41
- (0, _interceptor.prepareInterceptor)(element, 'value', valueInterceptor);
42
- }
43
-
44
- function setUIValue(element, value) {
45
- element.value = {
46
- [UIValue]: UIValue,
47
- toString: () => value
48
- };
49
- }
50
-
51
- function getUIValue(element) {
52
- return element[UIValue] === undefined ? element.value : String(element[UIValue]);
53
- }
54
-
55
- function setInitialValue(element) {
56
- element[InitialValue] = element.value;
57
- }
58
-
59
- function getInitialValue(element) {
60
- return element[InitialValue];
61
- }
62
-
63
- function startTrackValue(element) {
64
- element[TrackChanges] = [];
65
- }
66
-
67
- function trackValue(element, v) {
68
- var _element$TrackChanges;
69
-
70
- (_element$TrackChanges = element[TrackChanges]) == null ? void 0 : _element$TrackChanges.push(v);
71
- }
72
-
73
- function endTrackValue(element) {
74
- const tracked = element[TrackChanges];
75
- element[TrackChanges] = undefined;
76
- return tracked;
77
- }
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
- }
package/dist/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { specialCharMap } from './keyboard';
2
- import { UserEventApis, setup } from './setup';
3
- declare const userEvent: UserEventApis & {
4
- setup: typeof setup;
5
- };
6
- export default userEvent;
7
- export { specialCharMap as specialChars };
8
- export type { keyboardKey } from './keyboard';
package/dist/index.js DELETED
@@ -1,22 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- Object.defineProperty(exports, "specialChars", {
8
- enumerable: true,
9
- get: function () {
10
- return _keyboard.specialCharMap;
11
- }
12
- });
13
-
14
- var _keyboard = require("./keyboard");
15
-
16
- var _setup = require("./setup");
17
-
18
- const userEvent = { ...Object.fromEntries(Object.entries(_setup.userEventApis).map(([k, f]) => [k, (...a) => f.apply(userEvent, a)])),
19
- setup: _setup.setup
20
- };
21
- var _default = userEvent;
22
- exports.default = _default;
@@ -1,17 +0,0 @@
1
- import { keyboardKey, keyboardState } from './types';
2
- export declare function getKeyEventProps(keyDef: keyboardKey, state: keyboardState): {
3
- key: string | undefined;
4
- code: string | undefined;
5
- altKey: boolean;
6
- ctrlKey: boolean;
7
- metaKey: boolean;
8
- shiftKey: boolean;
9
- /** @deprecated use code instead */
10
- keyCode: number | undefined;
11
- };
12
- export declare function getMouseEventProps(state: keyboardState): {
13
- altKey: boolean;
14
- ctrlKey: boolean;
15
- metaKey: boolean;
16
- shiftKey: boolean;
17
- };
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getKeyEventProps = getKeyEventProps;
7
- exports.getMouseEventProps = getMouseEventProps;
8
-
9
- function getKeyEventProps(keyDef, state) {
10
- var _keyDef$keyCode, _keyDef$key;
11
-
12
- return {
13
- key: keyDef.key,
14
- code: keyDef.code,
15
- altKey: state.modifiers.alt,
16
- ctrlKey: state.modifiers.ctrl,
17
- metaKey: state.modifiers.meta,
18
- shiftKey: state.modifiers.shift,
19
-
20
- /** @deprecated use code instead */
21
- keyCode: (_keyDef$keyCode = keyDef.keyCode) != null ? _keyDef$keyCode : // istanbul ignore next
22
- ((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 ? keyDef.key.charCodeAt(0) : undefined
23
- };
24
- }
25
-
26
- function getMouseEventProps(state) {
27
- return {
28
- altKey: state.modifiers.alt,
29
- ctrlKey: state.modifiers.ctrl,
30
- metaKey: state.modifiers.meta,
31
- shiftKey: state.modifiers.shift
32
- };
33
- }