@testing-library/user-event 14.0.0-alpha.13 → 14.0.0-alpha.17

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 (92) 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 -5
  18. package/dist/index.js +7 -8
  19. package/dist/keyboard/index.d.ts +6 -17
  20. package/dist/keyboard/index.js +13 -41
  21. package/dist/keyboard/keyboardAction.d.ts +10 -0
  22. package/dist/keyboard/keyboardAction.js +156 -0
  23. package/dist/keyboard/{getNextKeyDef.d.ts → parseKeyDef.d.ts} +4 -5
  24. package/dist/keyboard/parseKeyDef.js +61 -0
  25. package/dist/keyboard/plugins/character.js +16 -10
  26. package/dist/keyboard/plugins/combination.js +3 -1
  27. package/dist/keyboard/plugins/functional.js +38 -20
  28. package/dist/keyboard/types.d.ts +3 -17
  29. package/dist/options.d.ts +102 -0
  30. package/dist/options.js +36 -0
  31. package/dist/pointer/index.d.ts +6 -14
  32. package/dist/pointer/index.js +8 -42
  33. package/dist/pointer/parseKeyDef.d.ts +2 -2
  34. package/dist/pointer/parseKeyDef.js +1 -3
  35. package/dist/pointer/pointerAction.d.ts +3 -2
  36. package/dist/pointer/pointerAction.js +9 -15
  37. package/dist/pointer/pointerMove.d.ts +2 -1
  38. package/dist/pointer/pointerPress.d.ts +2 -1
  39. package/dist/pointer/types.d.ts +0 -11
  40. package/dist/setup/api.d.ts +5 -0
  41. package/dist/setup/api.js +111 -0
  42. package/dist/setup/config.d.ts +10 -0
  43. package/dist/setup/config.js +8 -0
  44. package/dist/setup/directApi.d.ts +20 -0
  45. package/dist/setup/directApi.js +95 -0
  46. package/dist/setup/index.d.ts +30 -0
  47. package/dist/setup/index.js +27 -0
  48. package/dist/setup/setup.d.ts +74 -0
  49. package/dist/setup/setup.js +98 -0
  50. package/dist/setup/wrapAsync.d.ts +4 -0
  51. package/dist/setup/wrapAsync.js +15 -0
  52. package/dist/{clear.d.ts → utility/clear.d.ts} +2 -2
  53. package/dist/{clear.js → utility/clear.js} +2 -5
  54. package/dist/utility/index.d.ts +4 -0
  55. package/dist/utility/index.js +57 -0
  56. package/dist/utility/selectOptions.d.ts +3 -0
  57. package/dist/{selectOptions.js → utility/selectOptions.js} +15 -24
  58. package/dist/utility/type.d.ts +9 -0
  59. package/dist/utility/type.js +37 -0
  60. package/dist/utility/upload.d.ts +5 -0
  61. package/dist/{upload.js → utility/upload.js} +14 -40
  62. package/dist/utils/dataTransfer/Clipboard.d.ts +2 -0
  63. package/dist/utils/dataTransfer/Clipboard.js +45 -0
  64. package/dist/utils/dataTransfer/DataTransfer.d.ts +1 -0
  65. package/dist/utils/dataTransfer/DataTransfer.js +15 -0
  66. package/dist/utils/dataTransfer/FileList.js +13 -3
  67. package/dist/utils/edit/setFiles.d.ts +12 -0
  68. package/dist/utils/edit/setFiles.js +72 -0
  69. package/dist/utils/focus/copySelection.d.ts +1 -0
  70. package/dist/utils/focus/copySelection.js +36 -0
  71. package/dist/utils/index.d.ts +2 -0
  72. package/dist/utils/index.js +26 -0
  73. package/dist/utils/misc/getDocumentFromNode.d.ts +1 -0
  74. package/dist/utils/misc/getDocumentFromNode.js +14 -0
  75. package/package.json +1 -1
  76. package/dist/click.d.ts +0 -9
  77. package/dist/click.js +0 -61
  78. package/dist/hover.d.ts +0 -4
  79. package/dist/hover.js +0 -43
  80. package/dist/keyboard/getNextKeyDef.js +0 -55
  81. package/dist/keyboard/keyboardImplementation.d.ts +0 -3
  82. package/dist/keyboard/keyboardImplementation.js +0 -165
  83. package/dist/paste.d.ts +0 -6
  84. package/dist/paste.js +0 -64
  85. package/dist/selectOptions.d.ts +0 -4
  86. package/dist/setup.d.ts +0 -92
  87. package/dist/setup.js +0 -217
  88. package/dist/tab.d.ts +0 -5
  89. package/dist/tab.js +0 -12
  90. package/dist/type.d.ts +0 -14
  91. package/dist/type.js +0 -74
  92. package/dist/upload.d.ts +0 -9
@@ -1,165 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.keyboardImplementation = keyboardImplementation;
7
- exports.releaseAllKeys = releaseAllKeys;
8
-
9
- var _dom = require("@testing-library/dom");
10
-
11
- var _utils = require("../utils");
12
-
13
- var _getNextKeyDef = require("./getNextKeyDef");
14
-
15
- var plugins = _interopRequireWildcard(require("./plugins"));
16
-
17
- var _getEventProps = require("./getEventProps");
18
-
19
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20
-
21
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
-
23
- async function keyboardImplementation(text, options, state) {
24
- var _state$repeatKey;
25
-
26
- const {
27
- document
28
- } = options;
29
-
30
- const getCurrentElement = () => getActive(document);
31
-
32
- const {
33
- keyDef,
34
- consumedLength,
35
- releasePrevious,
36
- releaseSelf,
37
- repeat
38
- } = (_state$repeatKey = state.repeatKey) != null ? _state$repeatKey : (0, _getNextKeyDef.getNextKeyDef)(text, options);
39
- const pressed = state.pressed.find(p => p.keyDef === keyDef); // Release the key automatically if it was pressed before.
40
- // Do not release the key on iterations on `state.repeatKey`.
41
-
42
- if (pressed && !state.repeatKey) {
43
- keyup(keyDef, getCurrentElement, options, state, pressed.unpreventedDefault);
44
- }
45
-
46
- if (!releasePrevious) {
47
- const unpreventedDefault = keydown(keyDef, getCurrentElement, options, state);
48
-
49
- if (unpreventedDefault && hasKeyPress(keyDef, state)) {
50
- keypress(keyDef, getCurrentElement, options, state);
51
- } // Release the key only on the last iteration on `state.repeatKey`.
52
-
53
-
54
- if (releaseSelf && repeat <= 1) {
55
- keyup(keyDef, getCurrentElement, options, state, unpreventedDefault);
56
- }
57
- }
58
-
59
- if (repeat > 1) {
60
- state.repeatKey = {
61
- // don't consume again on the next iteration
62
- consumedLength: 0,
63
- keyDef,
64
- releasePrevious,
65
- releaseSelf,
66
- repeat: repeat - 1
67
- };
68
- } else {
69
- delete state.repeatKey;
70
- }
71
-
72
- if (text.length > consumedLength || repeat > 1) {
73
- if (options.delay > 0) {
74
- await (0, _utils.wait)(options.delay);
75
- }
76
-
77
- return keyboardImplementation(text.slice(consumedLength), options, state);
78
- }
79
-
80
- return void undefined;
81
- }
82
-
83
- function getActive(document) {
84
- var _getActiveElement;
85
-
86
- return (_getActiveElement = (0, _utils.getActiveElement)(document)) != null ? _getActiveElement :
87
- /* istanbul ignore next */
88
- document.body;
89
- }
90
-
91
- function releaseAllKeys(options, state) {
92
- const getCurrentElement = () => getActive(options.document);
93
-
94
- for (const k of state.pressed) {
95
- keyup(k.keyDef, getCurrentElement, options, state, k.unpreventedDefault);
96
- }
97
- }
98
-
99
- function keydown(keyDef, getCurrentElement, options, state) {
100
- const element = getCurrentElement(); // clear carried characters when focus is moved
101
-
102
- if (element !== state.activeElement) {
103
- state.carryValue = undefined;
104
- state.carryChar = '';
105
- }
106
-
107
- state.activeElement = element;
108
- applyPlugins(plugins.preKeydownBehavior, keyDef, element, options, state);
109
-
110
- const unpreventedDefault = _dom.fireEvent.keyDown(element, (0, _getEventProps.getKeyEventProps)(keyDef, state));
111
-
112
- state.pressed.push({
113
- keyDef,
114
- unpreventedDefault
115
- });
116
-
117
- if (unpreventedDefault) {
118
- // all default behavior like keypress/submit etc is applied to the currentElement
119
- applyPlugins(plugins.keydownBehavior, keyDef, getCurrentElement(), options, state);
120
- }
121
-
122
- return unpreventedDefault;
123
- }
124
-
125
- function keypress(keyDef, getCurrentElement, options, state) {
126
- const element = getCurrentElement();
127
-
128
- const unpreventedDefault = _dom.fireEvent.keyPress(element, { ...(0, _getEventProps.getKeyEventProps)(keyDef, state),
129
- charCode: keyDef.key === 'Enter' ? 13 : String(keyDef.key).charCodeAt(0)
130
- });
131
-
132
- if (unpreventedDefault) {
133
- applyPlugins(plugins.keypressBehavior, keyDef, getCurrentElement(), options, state);
134
- }
135
- }
136
-
137
- function keyup(keyDef, getCurrentElement, options, state, unprevented) {
138
- const element = getCurrentElement();
139
- applyPlugins(plugins.preKeyupBehavior, keyDef, element, options, state);
140
-
141
- const unpreventedDefault = _dom.fireEvent.keyUp(element, (0, _getEventProps.getKeyEventProps)(keyDef, state));
142
-
143
- if (unprevented && unpreventedDefault) {
144
- applyPlugins(plugins.keyupBehavior, keyDef, getCurrentElement(), options, state);
145
- }
146
-
147
- state.pressed = state.pressed.filter(k => k.keyDef !== keyDef);
148
- applyPlugins(plugins.postKeyupBehavior, keyDef, element, options, state);
149
- }
150
-
151
- function applyPlugins(pluginCollection, keyDef, element, options, state) {
152
- const plugin = pluginCollection.find(p => p.matches(keyDef, element, options, state));
153
-
154
- if (plugin) {
155
- plugin.handle(keyDef, element, options, state);
156
- }
157
-
158
- return !!plugin;
159
- }
160
-
161
- function hasKeyPress(keyDef, state) {
162
- var _keyDef$key;
163
-
164
- return (((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 || keyDef.key === 'Enter') && !state.modifiers.ctrl && !state.modifiers.alt;
165
- }
package/dist/paste.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import type { UserEvent } from './setup';
2
- export interface pasteOptions {
3
- document?: Document;
4
- }
5
- export declare function paste(this: UserEvent, clipboardData?: undefined, options?: pasteOptions): Promise<void>;
6
- export declare function paste(this: UserEvent, clipboardData: DataTransfer | string, options?: pasteOptions): void;
package/dist/paste.js DELETED
@@ -1,64 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.paste = paste;
7
-
8
- var _dom = require("@testing-library/dom");
9
-
10
- var _utils = require("./utils");
11
-
12
- function paste(clipboardData, options) {
13
- var _options$document, _doc$activeElement;
14
-
15
- const doc = (_options$document = options == null ? void 0 : options.document) != null ? _options$document : document;
16
- const target = (_doc$activeElement = doc.activeElement) != null ? _doc$activeElement :
17
- /* istanbul ignore next */
18
- doc.body;
19
- const data = typeof clipboardData === 'string' ? getClipboardDataFromString(clipboardData) : clipboardData;
20
- return data ? pasteImpl(target, data) : readClipboardDataFromClipboardApi(doc).then(dt => pasteImpl(target, dt));
21
- }
22
-
23
- function pasteImpl(target, clipboardData) {
24
- _dom.fireEvent.paste(target, {
25
- clipboardData
26
- });
27
-
28
- if ((0, _utils.isEditable)(target)) {
29
- const data = clipboardData.getData('text').substr(0, (0, _utils.getSpaceUntilMaxLength)(target));
30
-
31
- if (data) {
32
- var _prepareInput;
33
-
34
- (_prepareInput = (0, _utils.prepareInput)(data, target, 'insertFromPaste')) == null ? void 0 : _prepareInput.commit();
35
- }
36
- }
37
- }
38
-
39
- function getClipboardDataFromString(text) {
40
- const dt = (0, _utils.createDataTransfer)();
41
- dt.setData('text', text);
42
- return dt;
43
- }
44
-
45
- async function readClipboardDataFromClipboardApi(document) {
46
- var _document$defaultView;
47
-
48
- const clipboard = (_document$defaultView = document.defaultView) == null ? void 0 : _document$defaultView.navigator.clipboard;
49
- const items = clipboard && (await clipboard.read());
50
-
51
- if (!items) {
52
- throw new Error('`userEvent.paste()` without `clipboardData` requires the `ClipboardAPI` to be available.');
53
- }
54
-
55
- const dt = (0, _utils.createDataTransfer)();
56
-
57
- for (const item of items) {
58
- for (const type of item.types) {
59
- dt.setData(type, await item.getType(type).then(b => (0, _utils.readBlobText)(b)));
60
- }
61
- }
62
-
63
- return dt;
64
- }
@@ -1,4 +0,0 @@
1
- import { PointerOptions } from './utils';
2
- import type { UserEvent } from './setup';
3
- export declare function selectOptions(this: UserEvent, select: Element, values: HTMLElement | HTMLElement[] | string[] | string, options?: PointerOptions): void;
4
- export declare function deselectOptions(this: UserEvent, select: Element, values: HTMLElement | HTMLElement[] | string[] | string, options?: PointerOptions): void;
package/dist/setup.d.ts DELETED
@@ -1,92 +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 { paste } from './paste';
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
- dblClick: typeof dblClick;
18
- deselectOptions: typeof deselectOptions;
19
- hover: typeof hover;
20
- keyboard: typeof keyboard;
21
- paste: typeof paste;
22
- pointer: typeof pointer;
23
- selectOptions: typeof selectOptions;
24
- tab: typeof tab;
25
- tripleClick: typeof tripleClick;
26
- type: typeof type;
27
- unhover: typeof unhover;
28
- upload: typeof upload;
29
- };
30
- export declare type UserEventApis = typeof userEventApis;
31
- declare type setup = ReturnType<typeof _setup>['setup'];
32
- export declare type UserEvent = UserEventApis & {
33
- setup: setup;
34
- };
35
- declare type ClickOptions = Omit<clickOptions, 'clickCount'>;
36
- declare type KeyboardOptions = Partial<keyboardOptions>;
37
- declare type PointerApiOptions = Partial<pointerOptions>;
38
- declare type TabOptions = Omit<tabOptions, 'shift'>;
39
- declare type TypeOptions = Omit<typeOptions, 'initialSelectionStart' | 'initialSelectionEnd'>;
40
- declare type UploadOptions = uploadOptions;
41
- interface SetupOptions extends ClickOptions, KeyboardOptions, PointerOptions, PointerApiOptions, TabOptions, TypeOptions, UploadOptions {
42
- }
43
- /**
44
- * Start a "session" with userEvent.
45
- * All APIs returned by this function share an input device state and a default configuration.
46
- */
47
- export declare function setup(options?: SetupOptions): {
48
- clear: typeof clear;
49
- click: typeof click;
50
- dblClick: typeof dblClick;
51
- deselectOptions: typeof deselectOptions;
52
- hover: typeof hover;
53
- keyboard: typeof keyboard;
54
- paste: typeof paste;
55
- pointer: typeof pointer;
56
- selectOptions: typeof selectOptions;
57
- tab: typeof tab;
58
- tripleClick: typeof tripleClick;
59
- type: typeof type;
60
- unhover: typeof unhover;
61
- upload: typeof upload;
62
- } & {
63
- /**
64
- * Create a set of callbacks with different default settings but the same state.
65
- */
66
- setup(options: SetupOptions): {
67
- clear: typeof clear;
68
- click: typeof click;
69
- dblClick: typeof dblClick;
70
- deselectOptions: typeof deselectOptions;
71
- hover: typeof hover;
72
- keyboard: typeof keyboard;
73
- paste: typeof paste;
74
- pointer: typeof pointer;
75
- selectOptions: typeof selectOptions;
76
- tab: typeof tab;
77
- tripleClick: typeof tripleClick;
78
- type: typeof type;
79
- unhover: typeof unhover;
80
- upload: typeof upload;
81
- } & any;
82
- };
83
- declare function _setup({ applyAccept, autoModify, delay, document, keyboardMap, pointerMap, skipAutoClose, skipClick, skipHover, skipPointerEventsCheck, }: SetupOptions, { keyboardState, pointerState, }: {
84
- keyboardState: keyboardState;
85
- pointerState: pointerState;
86
- }): UserEventApis & {
87
- /**
88
- * Create a set of callbacks with different default settings but the same state.
89
- */
90
- setup(options: SetupOptions): ReturnType<typeof _setup>;
91
- };
92
- export {};
package/dist/setup.js DELETED
@@ -1,217 +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 _paste = require("./paste");
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
- dblClick: _click.dblClick,
37
- deselectOptions: _selectOptions.deselectOptions,
38
- hover: _hover.hover,
39
- keyboard: _keyboard.keyboard,
40
- paste: _paste.paste,
41
- pointer: _pointer.pointer,
42
- selectOptions: _selectOptions.selectOptions,
43
- tab: _tab.tab,
44
- tripleClick: _click.tripleClick,
45
- type: _type.type,
46
- unhover: _hover.unhover,
47
- upload: _upload.upload
48
- };
49
- exports.userEventApis = userEventApis;
50
-
51
- /**
52
- * Start a "session" with userEvent.
53
- * All APIs returned by this function share an input device state and a default configuration.
54
- */
55
- function setup(options = {}) {
56
- var _options$document, _doc$defaultView;
57
-
58
- const doc = (_options$document = options.document) != null ? _options$document : document;
59
- (0, _document.prepareDocument)(doc);
60
- const view = (_doc$defaultView = doc.defaultView) != null ? _doc$defaultView :
61
- /* istanbul ignore next */
62
- window;
63
- (0, _utils.attachClipboardStubToView)(view);
64
- return _setup(options, {
65
- keyboardState: (0, _keyboard.createKeyboardState)(),
66
- pointerState: (0, _pointer.createPointerState)()
67
- });
68
- }
69
-
70
- function _setup({
71
- applyAccept,
72
- autoModify,
73
- delay = 0,
74
- document,
75
- keyboardMap,
76
- pointerMap,
77
- skipAutoClose,
78
- skipClick,
79
- skipHover,
80
- skipPointerEventsCheck = false
81
- }, {
82
- keyboardState,
83
- pointerState
84
- }) {
85
- const keyboardDefaults = {
86
- autoModify,
87
- delay,
88
- document,
89
- keyboardMap
90
- };
91
- const pointerDefaults = {
92
- skipPointerEventsCheck
93
- };
94
- const pointerApiDefaults = {
95
- delay,
96
- pointerMap
97
- };
98
- const clickDefaults = {
99
- skipHover
100
- };
101
- const clipboardDefaults = {
102
- document
103
- };
104
- const typeDefaults = {
105
- delay,
106
- skipAutoClose,
107
- skipClick
108
- };
109
- const uploadDefaults = {
110
- applyAccept
111
- };
112
- const userEvent = {
113
- clear: (...args) => {
114
- return _clear.clear.call(userEvent, ...args);
115
- },
116
- click: (...args) => {
117
- args[1] = { ...pointerDefaults,
118
- ...clickDefaults,
119
- ...args[1]
120
- };
121
- return _click.click.call(userEvent, ...args);
122
- },
123
- dblClick: (...args) => {
124
- args[1] = { ...pointerDefaults,
125
- ...clickDefaults,
126
- ...args[1]
127
- };
128
- return _click.dblClick.call(userEvent, ...args);
129
- },
130
- deselectOptions: (...args) => {
131
- args[2] = { ...pointerDefaults,
132
- ...args[2]
133
- };
134
- return _selectOptions.deselectOptions.call(userEvent, ...args);
135
- },
136
- hover: (...args) => {
137
- args[1] = { ...pointerDefaults,
138
- ...args[1]
139
- };
140
- return _hover.hover.call(userEvent, ...args);
141
- },
142
- // keyboard needs typecasting because of the overloading
143
- keyboard: (...args) => {
144
- args[1] = { ...keyboardDefaults,
145
- ...args[1],
146
- keyboardState
147
- };
148
- const ret = (0, _keyboard.keyboard)(...args);
149
-
150
- if (ret instanceof Promise) {
151
- return ret.then(() => undefined);
152
- }
153
- },
154
- // paste needs typecasting because of the overloading
155
- paste: (...args) => {
156
- args[1] = { ...clipboardDefaults,
157
- ...args[1]
158
- };
159
- return _paste.paste.call(userEvent, ...args);
160
- },
161
- // pointer needs typecasting because of the overloading
162
- pointer: (...args) => {
163
- args[1] = { ...pointerApiDefaults,
164
- ...args[1],
165
- pointerState,
166
- keyboardState
167
- };
168
- const ret = (0, _pointer.pointer)(...args);
169
-
170
- if (ret instanceof Promise) {
171
- return ret.then(() => undefined);
172
- }
173
- },
174
- selectOptions: (...args) => {
175
- args[2] = { ...pointerDefaults,
176
- ...args[2]
177
- };
178
- return _selectOptions.selectOptions.call(userEvent, ...args);
179
- },
180
- setup: options => {
181
- return _setup({ ...keyboardDefaults,
182
- ...pointerDefaults,
183
- ...clickDefaults,
184
- ...options
185
- }, {
186
- keyboardState,
187
- pointerState
188
- });
189
- },
190
- tab: (...args) => {
191
- return _tab.tab.call(userEvent, ...args);
192
- },
193
- tripleClick: (...args) => {
194
- return _click.tripleClick.call(userEvent, ...args);
195
- },
196
- // type needs typecasting because of the overloading
197
- type: (...args) => {
198
- args[2] = { ...typeDefaults,
199
- ...args[2]
200
- };
201
- return _type.type.call(userEvent, ...args);
202
- },
203
- unhover: (...args) => {
204
- args[1] = { ...pointerDefaults,
205
- ...args[1]
206
- };
207
- return _hover.unhover.call(userEvent, ...args);
208
- },
209
- upload: (...args) => {
210
- args[3] = { ...uploadDefaults,
211
- ...args[3]
212
- };
213
- return _upload.upload.call(userEvent, ...args);
214
- }
215
- };
216
- return userEvent;
217
- }
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 {};