@testing-library/user-event 14.0.0-alpha.14 → 14.0.0-alpha.18

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 (82) hide show
  1. package/dist/clipboard/copy.d.ts +2 -11
  2. package/dist/clipboard/copy.js +10 -4
  3. package/dist/clipboard/cut.d.ts +2 -11
  4. package/dist/clipboard/cut.js +10 -4
  5. package/dist/clipboard/paste.d.ts +2 -6
  6. package/dist/clipboard/paste.js +7 -5
  7. package/dist/convenience/click.d.ts +4 -0
  8. package/dist/convenience/click.js +52 -0
  9. package/dist/convenience/hover.d.ts +3 -0
  10. package/dist/convenience/hover.js +31 -0
  11. package/dist/convenience/index.d.ts +3 -0
  12. package/dist/convenience/index.js +44 -0
  13. package/dist/convenience/tab.d.ts +4 -0
  14. package/dist/convenience/tab.js +12 -0
  15. package/dist/index.d.ts +2 -5
  16. package/dist/index.js +7 -8
  17. package/dist/keyboard/index.d.ts +6 -17
  18. package/dist/keyboard/index.js +13 -41
  19. package/dist/keyboard/keyboardAction.d.ts +10 -0
  20. package/dist/keyboard/keyboardAction.js +156 -0
  21. package/dist/keyboard/{getNextKeyDef.d.ts → parseKeyDef.d.ts} +4 -5
  22. package/dist/keyboard/parseKeyDef.js +61 -0
  23. package/dist/keyboard/plugins/character.js +16 -10
  24. package/dist/keyboard/plugins/combination.js +3 -1
  25. package/dist/keyboard/plugins/functional.js +38 -20
  26. package/dist/keyboard/types.d.ts +3 -17
  27. package/dist/options.d.ts +102 -0
  28. package/dist/options.js +36 -0
  29. package/dist/pointer/index.d.ts +6 -14
  30. package/dist/pointer/index.js +8 -42
  31. package/dist/pointer/parseKeyDef.d.ts +2 -2
  32. package/dist/pointer/parseKeyDef.js +1 -3
  33. package/dist/pointer/pointerAction.d.ts +3 -2
  34. package/dist/pointer/pointerAction.js +9 -15
  35. package/dist/pointer/pointerMove.d.ts +2 -1
  36. package/dist/pointer/pointerPress.d.ts +2 -1
  37. package/dist/pointer/types.d.ts +0 -11
  38. package/dist/setup/api.d.ts +5 -0
  39. package/dist/setup/api.js +111 -0
  40. package/dist/setup/config.d.ts +10 -0
  41. package/dist/setup/config.js +8 -0
  42. package/dist/setup/directApi.d.ts +20 -0
  43. package/dist/setup/directApi.js +95 -0
  44. package/dist/setup/index.d.ts +30 -0
  45. package/dist/setup/index.js +27 -0
  46. package/dist/setup/setup.d.ts +74 -0
  47. package/dist/setup/setup.js +98 -0
  48. package/dist/setup/wrapAsync.d.ts +4 -0
  49. package/dist/setup/wrapAsync.js +15 -0
  50. package/dist/{clear.d.ts → utility/clear.d.ts} +2 -2
  51. package/dist/{clear.js → utility/clear.js} +2 -5
  52. package/dist/utility/index.d.ts +4 -0
  53. package/dist/utility/index.js +57 -0
  54. package/dist/utility/selectOptions.d.ts +3 -0
  55. package/dist/{selectOptions.js → utility/selectOptions.js} +15 -24
  56. package/dist/utility/type.d.ts +9 -0
  57. package/dist/utility/type.js +37 -0
  58. package/dist/utility/upload.d.ts +5 -0
  59. package/dist/{upload.js → utility/upload.js} +12 -40
  60. package/dist/utils/dataTransfer/FileList.js +13 -3
  61. package/dist/utils/edit/setFiles.d.ts +12 -0
  62. package/dist/utils/edit/setFiles.js +72 -0
  63. package/dist/utils/index.d.ts +2 -0
  64. package/dist/utils/index.js +26 -0
  65. package/dist/utils/misc/getDocumentFromNode.d.ts +1 -0
  66. package/dist/utils/misc/getDocumentFromNode.js +14 -0
  67. package/package.json +1 -1
  68. package/dist/click.d.ts +0 -9
  69. package/dist/click.js +0 -61
  70. package/dist/hover.d.ts +0 -4
  71. package/dist/hover.js +0 -43
  72. package/dist/keyboard/getNextKeyDef.js +0 -55
  73. package/dist/keyboard/keyboardImplementation.d.ts +0 -3
  74. package/dist/keyboard/keyboardImplementation.js +0 -165
  75. package/dist/selectOptions.d.ts +0 -4
  76. package/dist/setup.d.ts +0 -100
  77. package/dist/setup.js +0 -241
  78. package/dist/tab.d.ts +0 -5
  79. package/dist/tab.js +0 -12
  80. package/dist/type.d.ts +0 -14
  81. package/dist/type.js +0 -74
  82. package/dist/upload.d.ts +0 -9
package/dist/setup.d.ts DELETED
@@ -1,100 +0,0 @@
1
- import { clear } from './clear';
2
- import { click, clickOptions, dblClick, tripleClick } from './click';
3
- import { hover, unhover } from './hover';
4
- import { keyboard, keyboardOptions } from './keyboard';
5
- import type { keyboardState } from './keyboard/types';
6
- import { copy, copyOptions, cut, cutOptions, paste, pasteOptions } from './clipboard';
7
- import { pointer } from './pointer';
8
- import type { pointerOptions, pointerState } from './pointer/types';
9
- import { deselectOptions, selectOptions } from './selectOptions';
10
- import { tab, tabOptions } from './tab';
11
- import { type, typeOptions } from './type';
12
- import { upload, uploadOptions } from './upload';
13
- import { PointerOptions } from './utils';
14
- export declare const userEventApis: {
15
- clear: typeof clear;
16
- click: typeof click;
17
- copy: typeof copy;
18
- cut: typeof cut;
19
- dblClick: typeof dblClick;
20
- deselectOptions: typeof deselectOptions;
21
- hover: typeof hover;
22
- keyboard: typeof keyboard;
23
- paste: typeof paste;
24
- pointer: typeof pointer;
25
- selectOptions: typeof selectOptions;
26
- tab: typeof tab;
27
- tripleClick: typeof tripleClick;
28
- type: typeof type;
29
- unhover: typeof unhover;
30
- upload: typeof upload;
31
- };
32
- export declare type UserEventApis = typeof userEventApis;
33
- declare type setup = ReturnType<typeof _setup>['setup'];
34
- export declare type UserEvent = UserEventApis & {
35
- setup: setup;
36
- };
37
- declare type ClickOptions = Omit<clickOptions, 'clickCount'>;
38
- interface ClipboardOptions extends copyOptions, cutOptions, pasteOptions {
39
- }
40
- declare type KeyboardOptions = Partial<keyboardOptions>;
41
- declare type PointerApiOptions = Partial<pointerOptions>;
42
- declare type TabOptions = Omit<tabOptions, 'shift'>;
43
- declare type TypeOptions = Omit<typeOptions, 'initialSelectionStart' | 'initialSelectionEnd'>;
44
- declare type UploadOptions = uploadOptions;
45
- interface SetupOptions extends ClickOptions, ClipboardOptions, KeyboardOptions, PointerOptions, PointerApiOptions, TabOptions, TypeOptions, UploadOptions {
46
- }
47
- /**
48
- * Start a "session" with userEvent.
49
- * All APIs returned by this function share an input device state and a default configuration.
50
- */
51
- export declare function setup(options?: SetupOptions): {
52
- clear: typeof clear;
53
- click: typeof click;
54
- copy: typeof copy;
55
- cut: typeof cut;
56
- dblClick: typeof dblClick;
57
- deselectOptions: typeof deselectOptions;
58
- hover: typeof hover;
59
- keyboard: typeof keyboard;
60
- paste: typeof paste;
61
- pointer: typeof pointer;
62
- selectOptions: typeof selectOptions;
63
- tab: typeof tab;
64
- tripleClick: typeof tripleClick;
65
- type: typeof type;
66
- unhover: typeof unhover;
67
- upload: typeof upload;
68
- } & {
69
- /**
70
- * Create a set of callbacks with different default settings but the same state.
71
- */
72
- setup(options: SetupOptions): {
73
- clear: typeof clear;
74
- click: typeof click;
75
- copy: typeof copy;
76
- cut: typeof cut;
77
- dblClick: typeof dblClick;
78
- deselectOptions: typeof deselectOptions;
79
- hover: typeof hover;
80
- keyboard: typeof keyboard;
81
- paste: typeof paste;
82
- pointer: typeof pointer;
83
- selectOptions: typeof selectOptions;
84
- tab: typeof tab;
85
- tripleClick: typeof tripleClick;
86
- type: typeof type;
87
- unhover: typeof unhover;
88
- upload: typeof upload;
89
- } & any;
90
- };
91
- declare function _setup({ applyAccept, autoModify, delay, document, keyboardMap, pointerMap, skipAutoClose, skipClick, skipHover, skipPointerEventsCheck, writeToClipboard, }: SetupOptions, { keyboardState, pointerState, }: {
92
- keyboardState: keyboardState;
93
- pointerState: pointerState;
94
- }): UserEventApis & {
95
- /**
96
- * Create a set of callbacks with different default settings but the same state.
97
- */
98
- setup(options: SetupOptions): ReturnType<typeof _setup>;
99
- };
100
- export {};
package/dist/setup.js DELETED
@@ -1,241 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.setup = setup;
7
- exports.userEventApis = void 0;
8
-
9
- var _clear = require("./clear");
10
-
11
- var _click = require("./click");
12
-
13
- var _document = require("./document");
14
-
15
- var _hover = require("./hover");
16
-
17
- var _keyboard = require("./keyboard");
18
-
19
- var _clipboard = require("./clipboard");
20
-
21
- var _pointer = require("./pointer");
22
-
23
- var _selectOptions = require("./selectOptions");
24
-
25
- var _tab = require("./tab");
26
-
27
- var _type = require("./type");
28
-
29
- var _upload = require("./upload");
30
-
31
- var _utils = require("./utils");
32
-
33
- const userEventApis = {
34
- clear: _clear.clear,
35
- click: _click.click,
36
- copy: _clipboard.copy,
37
- cut: _clipboard.cut,
38
- dblClick: _click.dblClick,
39
- deselectOptions: _selectOptions.deselectOptions,
40
- hover: _hover.hover,
41
- keyboard: _keyboard.keyboard,
42
- paste: _clipboard.paste,
43
- pointer: _pointer.pointer,
44
- selectOptions: _selectOptions.selectOptions,
45
- tab: _tab.tab,
46
- tripleClick: _click.tripleClick,
47
- type: _type.type,
48
- unhover: _hover.unhover,
49
- upload: _upload.upload
50
- };
51
- exports.userEventApis = userEventApis;
52
-
53
- /**
54
- * Start a "session" with userEvent.
55
- * All APIs returned by this function share an input device state and a default configuration.
56
- */
57
- function setup(options = {}) {
58
- var _options$document, _doc$defaultView;
59
-
60
- const doc = (_options$document = options.document) != null ? _options$document : document;
61
- (0, _document.prepareDocument)(doc);
62
- const view = (_doc$defaultView = doc.defaultView) != null ? _doc$defaultView :
63
- /* istanbul ignore next */
64
- window;
65
- (0, _utils.attachClipboardStubToView)(view);
66
- return _setup(options, {
67
- keyboardState: (0, _keyboard.createKeyboardState)(),
68
- pointerState: (0, _pointer.createPointerState)()
69
- });
70
- }
71
-
72
- function _setup({
73
- applyAccept,
74
- autoModify,
75
- delay = 0,
76
- document,
77
- keyboardMap,
78
- pointerMap,
79
- skipAutoClose,
80
- skipClick,
81
- skipHover,
82
- skipPointerEventsCheck = false,
83
- // Changing default return type from DataTransfer to Promise<DataTransfer>
84
- // would require a lot of overloading right now.
85
- // The APIs returned by setup will most likely be changed to async before stable release anyway.
86
- // See https://github.com/testing-library/user-event/issues/504#issuecomment-944883855
87
- // So the default option can be changed during alpha instead of introducing too much code here.
88
- // TODO: This should default to true
89
- writeToClipboard = false
90
- }, {
91
- keyboardState,
92
- pointerState
93
- }) {
94
- const keyboardDefaults = {
95
- autoModify,
96
- delay,
97
- document,
98
- keyboardMap
99
- };
100
- const pointerDefaults = {
101
- skipPointerEventsCheck
102
- };
103
- const pointerApiDefaults = {
104
- delay,
105
- pointerMap
106
- };
107
- const clickDefaults = {
108
- skipHover
109
- };
110
- const clipboardDefaults = {
111
- document,
112
- writeToClipboard
113
- };
114
- const typeDefaults = {
115
- delay,
116
- skipAutoClose,
117
- skipClick
118
- };
119
- const uploadDefaults = {
120
- applyAccept
121
- };
122
- const userEvent = {
123
- clear: (...args) => {
124
- return _clear.clear.call(userEvent, ...args);
125
- },
126
- click: (...args) => {
127
- args[1] = { ...pointerDefaults,
128
- ...clickDefaults,
129
- ...args[1]
130
- };
131
- return _click.click.call(userEvent, ...args);
132
- },
133
- // copy needs typecasting because of the overloading
134
- copy: (...args) => {
135
- args[0] = { ...clipboardDefaults,
136
- ...args[0]
137
- };
138
- return _clipboard.copy.call(userEvent, ...args);
139
- },
140
- // cut needs typecasting because of the overloading
141
- cut: (...args) => {
142
- args[0] = { ...clipboardDefaults,
143
- ...args[0]
144
- };
145
- return _clipboard.cut.call(userEvent, ...args);
146
- },
147
- dblClick: (...args) => {
148
- args[1] = { ...pointerDefaults,
149
- ...clickDefaults,
150
- ...args[1]
151
- };
152
- return _click.dblClick.call(userEvent, ...args);
153
- },
154
- deselectOptions: (...args) => {
155
- args[2] = { ...pointerDefaults,
156
- ...args[2]
157
- };
158
- return _selectOptions.deselectOptions.call(userEvent, ...args);
159
- },
160
- hover: (...args) => {
161
- args[1] = { ...pointerDefaults,
162
- ...args[1]
163
- };
164
- return _hover.hover.call(userEvent, ...args);
165
- },
166
- // keyboard needs typecasting because of the overloading
167
- keyboard: (...args) => {
168
- args[1] = { ...keyboardDefaults,
169
- ...args[1],
170
- keyboardState
171
- };
172
- const ret = (0, _keyboard.keyboard)(...args);
173
-
174
- if (ret instanceof Promise) {
175
- return ret.then(() => undefined);
176
- }
177
- },
178
- // paste needs typecasting because of the overloading
179
- paste: (...args) => {
180
- args[1] = { ...clipboardDefaults,
181
- ...args[1]
182
- };
183
- return _clipboard.paste.call(userEvent, ...args);
184
- },
185
- // pointer needs typecasting because of the overloading
186
- pointer: (...args) => {
187
- args[1] = { ...pointerApiDefaults,
188
- ...args[1],
189
- pointerState,
190
- keyboardState
191
- };
192
- const ret = (0, _pointer.pointer)(...args);
193
-
194
- if (ret instanceof Promise) {
195
- return ret.then(() => undefined);
196
- }
197
- },
198
- selectOptions: (...args) => {
199
- args[2] = { ...pointerDefaults,
200
- ...args[2]
201
- };
202
- return _selectOptions.selectOptions.call(userEvent, ...args);
203
- },
204
- setup: options => {
205
- return _setup({ ...keyboardDefaults,
206
- ...pointerDefaults,
207
- ...clickDefaults,
208
- ...options
209
- }, {
210
- keyboardState,
211
- pointerState
212
- });
213
- },
214
- tab: (...args) => {
215
- return _tab.tab.call(userEvent, ...args);
216
- },
217
- tripleClick: (...args) => {
218
- return _click.tripleClick.call(userEvent, ...args);
219
- },
220
- // type needs typecasting because of the overloading
221
- type: (...args) => {
222
- args[2] = { ...typeDefaults,
223
- ...args[2]
224
- };
225
- return _type.type.call(userEvent, ...args);
226
- },
227
- unhover: (...args) => {
228
- args[1] = { ...pointerDefaults,
229
- ...args[1]
230
- };
231
- return _hover.unhover.call(userEvent, ...args);
232
- },
233
- upload: (...args) => {
234
- args[3] = { ...uploadDefaults,
235
- ...args[3]
236
- };
237
- return _upload.upload.call(userEvent, ...args);
238
- }
239
- };
240
- return userEvent;
241
- }
package/dist/tab.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- export interface tabOptions {
3
- shift?: boolean;
4
- }
5
- export declare function tab(this: UserEvent, { shift }?: tabOptions): void;
package/dist/tab.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.tab = tab;
7
-
8
- function tab({
9
- shift
10
- } = {}) {
11
- this.keyboard(shift === true ? '{Shift>}{Tab}{/Shift}' : shift === false ? '[/ShiftLeft][/ShiftRight]{Tab}' : '{Tab}');
12
- }
package/dist/type.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- export interface typeOptions {
3
- delay?: number;
4
- skipClick?: boolean;
5
- skipAutoClose?: boolean;
6
- initialSelectionStart?: number;
7
- initialSelectionEnd?: number;
8
- }
9
- export declare function type(this: UserEvent, element: Element, text: string, options?: typeOptions & {
10
- delay?: 0;
11
- }): void;
12
- export declare function type(this: UserEvent, element: Element, text: string, options: typeOptions & {
13
- delay: number;
14
- }): Promise<void>;
package/dist/type.js DELETED
@@ -1,74 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.type = type;
7
-
8
- var _dom = require("@testing-library/dom");
9
-
10
- var _document = require("./document");
11
-
12
- var _utils = require("./utils");
13
-
14
- var _keyboard = require("./keyboard");
15
-
16
- // this needs to be wrapped in the event/asyncWrapper for React's act and angular's change detection
17
- // depending on whether it will be async.
18
- function type(element, text, {
19
- delay = 0,
20
- ...options
21
- } = {}) {
22
- (0, _document.prepareDocument)(element.ownerDocument); // we do not want to wrap in the asyncWrapper if we're not
23
- // going to actually be doing anything async, so we only wrap
24
- // if the delay is greater than 0
25
-
26
- if (delay > 0) {
27
- return (0, _dom.getConfig)().asyncWrapper(() => typeImplementation(this, element, text, {
28
- delay,
29
- ...options
30
- }));
31
- } else {
32
- return void typeImplementation(this, element, text, {
33
- delay,
34
- ...options
35
- }) // prevents users from dealing with UnhandledPromiseRejectionWarning
36
- .catch(console.error);
37
- }
38
- }
39
-
40
- async function typeImplementation(userEvent, element, text, {
41
- delay,
42
- skipClick = false,
43
- skipAutoClose = false,
44
- initialSelectionStart = undefined,
45
- initialSelectionEnd = undefined
46
- }) {
47
- // TODO: properly type guard
48
- // we use this workaround for now to prevent changing behavior
49
- if (element.disabled) return;
50
- if (!skipClick) userEvent.click(element);
51
-
52
- if (initialSelectionStart !== undefined) {
53
- (0, _utils.setSelectionRange)(element, initialSelectionStart, initialSelectionEnd != null ? initialSelectionEnd : initialSelectionStart);
54
- }
55
-
56
- const {
57
- promise,
58
- releaseAllKeys
59
- } = (0, _keyboard.keyboardImplementationWrapper)(text, {
60
- delay,
61
- document: element.ownerDocument
62
- });
63
-
64
- if (delay > 0) {
65
- await promise;
66
- }
67
-
68
- if (!skipAutoClose) {
69
- releaseAllKeys();
70
- } // eslint-disable-next-line consistent-return -- we need to return the internal Promise so that it is catchable if we don't await
71
-
72
-
73
- return promise;
74
- }
package/dist/upload.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- interface uploadInit {
3
- changeInit?: EventInit;
4
- }
5
- export interface uploadOptions {
6
- applyAccept?: boolean;
7
- }
8
- export declare function upload(this: UserEvent, element: HTMLElement, fileOrFiles: File | File[], init?: uploadInit, { applyAccept }?: uploadOptions): void;
9
- export {};