@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
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "clear", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _utility.clear;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "click", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _convenience.click;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "copy", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _clipboard.copy;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "cut", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _clipboard.cut;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "dblClick", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _convenience.dblClick;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "deselectOptions", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _utility.deselectOptions;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "hover", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _convenience.hover;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "keyboard", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _keyboard.keyboard;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "paste", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _clipboard.paste;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, "pointer", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _pointer.pointer;
64
+ }
65
+ });
66
+ Object.defineProperty(exports, "selectOptions", {
67
+ enumerable: true,
68
+ get: function () {
69
+ return _utility.selectOptions;
70
+ }
71
+ });
72
+ Object.defineProperty(exports, "tab", {
73
+ enumerable: true,
74
+ get: function () {
75
+ return _convenience.tab;
76
+ }
77
+ });
78
+ Object.defineProperty(exports, "tripleClick", {
79
+ enumerable: true,
80
+ get: function () {
81
+ return _convenience.tripleClick;
82
+ }
83
+ });
84
+ Object.defineProperty(exports, "type", {
85
+ enumerable: true,
86
+ get: function () {
87
+ return _utility.type;
88
+ }
89
+ });
90
+ Object.defineProperty(exports, "unhover", {
91
+ enumerable: true,
92
+ get: function () {
93
+ return _convenience.unhover;
94
+ }
95
+ });
96
+ Object.defineProperty(exports, "upload", {
97
+ enumerable: true,
98
+ get: function () {
99
+ return _utility.upload;
100
+ }
101
+ });
102
+
103
+ var _convenience = require("../convenience");
104
+
105
+ var _keyboard = require("../keyboard");
106
+
107
+ var _clipboard = require("../clipboard");
108
+
109
+ var _pointer = require("../pointer");
110
+
111
+ var _utility = require("../utility");
@@ -0,0 +1,10 @@
1
+ import type { keyboardState } from '../keyboard/types';
2
+ import type { pointerState } from '../pointer/types';
3
+ import type { Options } from '../options';
4
+ export interface inputDeviceState {
5
+ pointerState: pointerState;
6
+ keyboardState: keyboardState;
7
+ }
8
+ export interface Config extends Required<Options>, inputDeviceState {
9
+ }
10
+ export declare const Config: unique symbol;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Config = void 0;
7
+ const Config = Symbol('Config');
8
+ exports.Config = Config;
@@ -0,0 +1,20 @@
1
+ import type { PointerOptions } from '../utils';
2
+ import type { PointerInput } from '../pointer';
3
+ import type { UserEventApi } from '.';
4
+ import { Config } from './config';
5
+ export declare function clear(element: Element): Promise<void>;
6
+ export declare function click(element: Element, options?: Partial<Config>): Promise<void>;
7
+ export declare function copy(options?: Partial<Config>): Promise<DataTransfer | undefined>;
8
+ export declare function cut(options?: Partial<Config>): Promise<DataTransfer | undefined>;
9
+ export declare function dblClick(element: Element, options?: Partial<Config>): Promise<void>;
10
+ export declare function deselectOptions(select: Element, values: HTMLElement | HTMLElement[] | string[] | string, options?: Partial<Config>): Promise<void>;
11
+ export declare function hover(element: Element, options?: Partial<Config>): Promise<void>;
12
+ export declare function keyboard(text: string, options?: Partial<Config>): Promise<import("../keyboard").keyboardState>;
13
+ export declare function pointer(input: PointerInput, options?: Partial<Config>): Promise<import("../pointer").pointerState>;
14
+ export declare function paste(clipboardData?: DataTransfer | string, options?: Partial<Config>): Promise<void>;
15
+ export declare function selectOptions(select: Element, values: HTMLElement | HTMLElement[] | string[] | string, options?: Partial<Config>): Promise<void>;
16
+ export declare function tripleClick(element: Element, options?: Partial<Config>): Promise<void>;
17
+ export declare function type(element: Element, text: string, options?: Partial<Config> & Parameters<UserEventApi['type']>[2]): Promise<void>;
18
+ export declare function unhover(element: Element, options?: PointerOptions): Promise<void>;
19
+ export declare function upload(element: HTMLElement, fileOrFiles: File | File[], options?: Partial<Config>): Promise<void>;
20
+ export declare function tab(options?: Partial<Config> & Parameters<UserEventApi['tab']>[0]): Promise<void>;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.clear = clear;
7
+ exports.click = click;
8
+ exports.copy = copy;
9
+ exports.cut = cut;
10
+ exports.dblClick = dblClick;
11
+ exports.deselectOptions = deselectOptions;
12
+ exports.hover = hover;
13
+ exports.keyboard = keyboard;
14
+ exports.paste = paste;
15
+ exports.pointer = pointer;
16
+ exports.selectOptions = selectOptions;
17
+ exports.tab = tab;
18
+ exports.tripleClick = tripleClick;
19
+ exports.type = type;
20
+ exports.unhover = unhover;
21
+ exports.upload = upload;
22
+
23
+ var _setup = require("./setup");
24
+
25
+ var _config = require("./config");
26
+
27
+ function clear(element) {
28
+ return (0, _setup.setupDirect)().clear(element);
29
+ }
30
+
31
+ function click(element, options = {}) {
32
+ return (0, _setup.setupDirect)(options, element).click(element);
33
+ }
34
+
35
+ function copy(options = {}) {
36
+ return (0, _setup.setupDirect)(options).copy();
37
+ }
38
+
39
+ function cut(options = {}) {
40
+ return (0, _setup.setupDirect)(options).cut();
41
+ }
42
+
43
+ function dblClick(element, options = {}) {
44
+ return (0, _setup.setupDirect)(options).dblClick(element);
45
+ }
46
+
47
+ function deselectOptions(select, values, options = {}) {
48
+ return (0, _setup.setupDirect)(options).deselectOptions(select, values);
49
+ }
50
+
51
+ function hover(element, options = {}) {
52
+ return (0, _setup.setupDirect)(options).hover(element);
53
+ }
54
+
55
+ async function keyboard(text, options = {}) {
56
+ const instance = (0, _setup.setupDirect)(options);
57
+ const promise = instance.keyboard(text);
58
+ return promise.then(() => instance[_config.Config].keyboardState);
59
+ }
60
+
61
+ async function pointer(input, options = {}) {
62
+ const instance = (0, _setup.setupDirect)(options);
63
+ const promise = instance.pointer(input);
64
+ return promise.then(() => instance[_config.Config].pointerState);
65
+ }
66
+
67
+ function paste(clipboardData, options) {
68
+ return (0, _setup.setupDirect)(options).paste(clipboardData);
69
+ }
70
+
71
+ function selectOptions(select, values, options = {}) {
72
+ return (0, _setup.setupDirect)(options).selectOptions(select, values);
73
+ }
74
+
75
+ function tripleClick(element, options = {}) {
76
+ return (0, _setup.setupDirect)(options).tripleClick(element);
77
+ }
78
+
79
+ function type(element, text, options = {}) {
80
+ return (0, _setup.setupDirect)(options, element).type(element, text, options);
81
+ }
82
+
83
+ function unhover(element, options = {}) {
84
+ const instance = (0, _setup.setupDirect)(options);
85
+ instance[_config.Config].pointerState.position.mouse.target = element;
86
+ return instance.unhover(element);
87
+ }
88
+
89
+ function upload(element, fileOrFiles, options = {}) {
90
+ return (0, _setup.setupDirect)(options).upload(element, fileOrFiles);
91
+ }
92
+
93
+ function tab(options = {}) {
94
+ return (0, _setup.setupDirect)().tab(options);
95
+ }
@@ -0,0 +1,30 @@
1
+ import type * as userEventApi from './api';
2
+ import { setupMain, setupSub } from './setup';
3
+ import { Config, inputDeviceState } from './config';
4
+ import * as directApi from './directApi';
5
+ export type { inputDeviceState };
6
+ export { Config };
7
+ export declare type UserEventApi = typeof userEventApi;
8
+ export declare type UserEvent = UserEventApi & {
9
+ readonly setup: typeof setupSub;
10
+ [Config]: Config;
11
+ };
12
+ export declare const userEvent: {
13
+ readonly setup: typeof setupMain;
14
+ readonly clear: typeof directApi.clear;
15
+ readonly click: typeof directApi.click;
16
+ readonly copy: typeof directApi.copy;
17
+ readonly cut: typeof directApi.cut;
18
+ readonly dblClick: typeof directApi.dblClick;
19
+ readonly deselectOptions: typeof directApi.deselectOptions;
20
+ readonly hover: typeof directApi.hover;
21
+ readonly keyboard: typeof directApi.keyboard;
22
+ readonly pointer: typeof directApi.pointer;
23
+ readonly paste: typeof directApi.paste;
24
+ readonly selectOptions: typeof directApi.selectOptions;
25
+ readonly tripleClick: typeof directApi.tripleClick;
26
+ readonly type: typeof directApi.type;
27
+ readonly unhover: typeof directApi.unhover;
28
+ readonly upload: typeof directApi.upload;
29
+ readonly tab: typeof directApi.tab;
30
+ };
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Config", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _config.Config;
10
+ }
11
+ });
12
+ exports.userEvent = void 0;
13
+
14
+ var _setup = require("./setup");
15
+
16
+ var _config = require("./config");
17
+
18
+ var directApi = _interopRequireWildcard(require("./directApi"));
19
+
20
+ 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); }
21
+
22
+ 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; }
23
+
24
+ const userEvent = { ...directApi,
25
+ setup: _setup.setupMain
26
+ };
27
+ exports.userEvent = userEvent;
@@ -0,0 +1,74 @@
1
+ import { Options } from '../options';
2
+ import type { UserEvent } from './index';
3
+ import { Config } from './config';
4
+ import * as userEventApi from './api';
5
+ /**
6
+ * Start a "session" with userEvent.
7
+ * All APIs returned by this function share an input device state and a default configuration.
8
+ */
9
+ export declare function setupMain(options?: Options): {
10
+ setup: typeof setupSub;
11
+ [Config]: Config;
12
+ click: typeof userEventApi.click;
13
+ dblClick: typeof userEventApi.dblClick;
14
+ tripleClick: typeof userEventApi.tripleClick;
15
+ hover: typeof userEventApi.hover;
16
+ unhover: typeof userEventApi.unhover;
17
+ tab: typeof userEventApi.tab;
18
+ keyboard: typeof userEventApi.keyboard;
19
+ copy: typeof userEventApi.copy;
20
+ cut: typeof userEventApi.cut;
21
+ paste: typeof userEventApi.paste;
22
+ pointer: typeof userEventApi.pointer;
23
+ clear: typeof userEventApi.clear;
24
+ deselectOptions: typeof userEventApi.deselectOptions;
25
+ selectOptions: typeof userEventApi.selectOptions;
26
+ type: typeof userEventApi.type;
27
+ upload: typeof userEventApi.upload;
28
+ };
29
+ /**
30
+ * Setup in direct call per `userEvent.anyApi()`
31
+ */
32
+ export declare function setupDirect(options?: Partial<Config>, node?: Node): {
33
+ setup: typeof setupSub;
34
+ [Config]: Config;
35
+ click: typeof userEventApi.click;
36
+ dblClick: typeof userEventApi.dblClick;
37
+ tripleClick: typeof userEventApi.tripleClick;
38
+ hover: typeof userEventApi.hover;
39
+ unhover: typeof userEventApi.unhover;
40
+ tab: typeof userEventApi.tab;
41
+ keyboard: typeof userEventApi.keyboard;
42
+ copy: typeof userEventApi.copy;
43
+ cut: typeof userEventApi.cut;
44
+ paste: typeof userEventApi.paste;
45
+ pointer: typeof userEventApi.pointer;
46
+ clear: typeof userEventApi.clear;
47
+ deselectOptions: typeof userEventApi.deselectOptions;
48
+ selectOptions: typeof userEventApi.selectOptions;
49
+ type: typeof userEventApi.type;
50
+ upload: typeof userEventApi.upload;
51
+ };
52
+ /**
53
+ * Create a set of callbacks with different default settings but the same state.
54
+ */
55
+ export declare function setupSub(this: UserEvent, options: Options): {
56
+ setup: typeof setupSub;
57
+ [Config]: Config;
58
+ click: typeof userEventApi.click;
59
+ dblClick: typeof userEventApi.dblClick;
60
+ tripleClick: typeof userEventApi.tripleClick;
61
+ hover: typeof userEventApi.hover;
62
+ unhover: typeof userEventApi.unhover;
63
+ tab: typeof userEventApi.tab;
64
+ keyboard: typeof userEventApi.keyboard;
65
+ copy: typeof userEventApi.copy;
66
+ cut: typeof userEventApi.cut;
67
+ paste: typeof userEventApi.paste;
68
+ pointer: typeof userEventApi.pointer;
69
+ clear: typeof userEventApi.clear;
70
+ deselectOptions: typeof userEventApi.deselectOptions;
71
+ selectOptions: typeof userEventApi.selectOptions;
72
+ type: typeof userEventApi.type;
73
+ upload: typeof userEventApi.upload;
74
+ };
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setupDirect = setupDirect;
7
+ exports.setupMain = setupMain;
8
+ exports.setupSub = setupSub;
9
+
10
+ var _document = require("../document");
11
+
12
+ var _keyboard = require("../keyboard");
13
+
14
+ var _pointer = require("../pointer");
15
+
16
+ var _options = require("../options");
17
+
18
+ var _utils = require("../utils");
19
+
20
+ var _config = require("./config");
21
+
22
+ var userEventApi = _interopRequireWildcard(require("./api"));
23
+
24
+ var _wrapAsync = require("./wrapAsync");
25
+
26
+ 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); }
27
+
28
+ 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; }
29
+
30
+ /**
31
+ * Start a "session" with userEvent.
32
+ * All APIs returned by this function share an input device state and a default configuration.
33
+ */
34
+ function setupMain(options = {}) {
35
+ var _doc$defaultView;
36
+
37
+ const doc = getDocument(options);
38
+ (0, _document.prepareDocument)(doc);
39
+ const view = (_doc$defaultView = doc.defaultView) != null ? _doc$defaultView :
40
+ /* istanbul ignore next */
41
+ window;
42
+ (0, _utils.attachClipboardStubToView)(view);
43
+ return doSetup({ ..._options.defaultOptionsSetup,
44
+ keyboardState: (0, _keyboard.createKeyboardState)(),
45
+ pointerState: (0, _pointer.createPointerState)(doc)
46
+ });
47
+ }
48
+ /**
49
+ * Setup in direct call per `userEvent.anyApi()`
50
+ */
51
+
52
+
53
+ function setupDirect(options = {}, node) {
54
+ const doc = getDocument(options, node);
55
+ (0, _document.prepareDocument)(doc);
56
+ return doSetup({
57
+ keyboardState: (0, _keyboard.createKeyboardState)(),
58
+ pointerState: (0, _pointer.createPointerState)(doc),
59
+ ..._options.defaultOptionsDirect,
60
+ ...options
61
+ });
62
+ }
63
+ /**
64
+ * Create a set of callbacks with different default settings but the same state.
65
+ */
66
+
67
+
68
+ function setupSub(options) {
69
+ return doSetup({ ...this[_config.Config],
70
+ ...options
71
+ });
72
+ }
73
+
74
+ function wrapImpl(impl) {
75
+ function method(...args) {
76
+ return (0, _wrapAsync.wrapAsync)(() => impl.apply(this, args));
77
+ }
78
+
79
+ Object.defineProperty(method, 'name', {
80
+ get: () => impl.name
81
+ });
82
+ return method;
83
+ }
84
+
85
+ const wrappedApis = Object.fromEntries(Object.entries(userEventApi).map(([name, impl]) => [name, wrapImpl(impl)]));
86
+
87
+ function doSetup(config) {
88
+ return { ...wrappedApis,
89
+ setup: setupSub,
90
+ [_config.Config]: config
91
+ };
92
+ }
93
+
94
+ function getDocument(options, node) {
95
+ var _ref, _options$document;
96
+
97
+ return (_ref = (_options$document = options.document) != null ? _options$document : node && (0, _utils.getDocumentFromNode)(node)) != null ? _ref : document;
98
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Wrap an internal Promise
3
+ */
4
+ export declare function wrapAsync<R, P extends (() => Promise<R>) | (() => R)>(implementation: P): Promise<R>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.wrapAsync = wrapAsync;
7
+
8
+ var _dom = require("@testing-library/dom");
9
+
10
+ /**
11
+ * Wrap an internal Promise
12
+ */
13
+ function wrapAsync(implementation) {
14
+ return (0, _dom.getConfig)().asyncWrapper(implementation);
15
+ }
@@ -1,2 +1,2 @@
1
- import type { UserEvent } from './setup';
2
- export declare function clear(this: UserEvent, element: Element): void;
1
+ import type { UserEvent } from '../setup';
2
+ export declare function clear(this: UserEvent, element: Element): Promise<void>;
@@ -5,18 +5,15 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.clear = clear;
7
7
 
8
- var _document = require("./document");
8
+ var _utils = require("../utils");
9
9
 
10
- var _utils = require("./utils");
11
-
12
- function clear(element) {
10
+ async function clear(element) {
13
11
  var _prepareInput;
14
12
 
15
13
  if (!(0, _utils.isEditable)(element) || (0, _utils.isDisabled)(element)) {
16
14
  throw new Error('clear()` is only supported on editable elements.');
17
15
  }
18
16
 
19
- (0, _document.prepareDocument)(element.ownerDocument);
20
17
  (0, _utils.focus)(element);
21
18
 
22
19
  if (element.ownerDocument.activeElement !== element) {
@@ -0,0 +1,4 @@
1
+ export * from './clear';
2
+ export * from './selectOptions';
3
+ export * from './type';
4
+ export * from './upload';
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _clear = require("./clear");
8
+
9
+ Object.keys(_clear).forEach(function (key) {
10
+ if (key === "default" || key === "__esModule") return;
11
+ if (key in exports && exports[key] === _clear[key]) return;
12
+ Object.defineProperty(exports, key, {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _clear[key];
16
+ }
17
+ });
18
+ });
19
+
20
+ var _selectOptions = require("./selectOptions");
21
+
22
+ Object.keys(_selectOptions).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _selectOptions[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _selectOptions[key];
29
+ }
30
+ });
31
+ });
32
+
33
+ var _type = require("./type");
34
+
35
+ Object.keys(_type).forEach(function (key) {
36
+ if (key === "default" || key === "__esModule") return;
37
+ if (key in exports && exports[key] === _type[key]) return;
38
+ Object.defineProperty(exports, key, {
39
+ enumerable: true,
40
+ get: function () {
41
+ return _type[key];
42
+ }
43
+ });
44
+ });
45
+
46
+ var _upload = require("./upload");
47
+
48
+ Object.keys(_upload).forEach(function (key) {
49
+ if (key === "default" || key === "__esModule") return;
50
+ if (key in exports && exports[key] === _upload[key]) return;
51
+ Object.defineProperty(exports, key, {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _upload[key];
55
+ }
56
+ });
57
+ });
@@ -0,0 +1,3 @@
1
+ import { UserEvent } from '../setup';
2
+ export declare function selectOptions(this: UserEvent, select: Element, values: HTMLElement | HTMLElement[] | string[] | string): Promise<void>;
3
+ export declare function deselectOptions(this: UserEvent, select: Element, values: HTMLElement | HTMLElement[] | string[] | string): Promise<void>;
@@ -8,19 +8,19 @@ exports.selectOptions = selectOptions;
8
8
 
9
9
  var _dom = require("@testing-library/dom");
10
10
 
11
- var _utils = require("./utils");
11
+ var _utils = require("../utils");
12
12
 
13
- function selectOptions(select, values, options = {}) {
14
- return selectOptionsBase.call(this, true, select, values, options);
13
+ var _setup = require("../setup");
14
+
15
+ async function selectOptions(select, values) {
16
+ return selectOptionsBase.call(this, true, select, values);
15
17
  }
16
18
 
17
- function deselectOptions(select, values, options = {}) {
18
- return selectOptionsBase.call(this, false, select, values, options);
19
+ async function deselectOptions(select, values) {
20
+ return selectOptionsBase.call(this, false, select, values);
19
21
  }
20
22
 
21
- function selectOptionsBase(newValue, select, values, {
22
- skipPointerEventsCheck
23
- }) {
23
+ async function selectOptionsBase(newValue, select, values) {
24
24
  if (!newValue && !select.multiple) {
25
25
  throw (0, _dom.getConfig)().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
26
26
  }
@@ -45,7 +45,7 @@ function selectOptionsBase(newValue, select, values, {
45
45
  if ((0, _utils.isElementType)(select, 'select')) {
46
46
  if (select.multiple) {
47
47
  for (const option of selectedOptions) {
48
- const withPointerEvents = skipPointerEventsCheck ? true : (0, _utils.hasPointerEvents)(option); // events fired for multiple select are weird. Can't use hover...
48
+ const withPointerEvents = this[_setup.Config].skipPointerEventsCheck ? true : (0, _utils.hasPointerEvents)(option); // events fired for multiple select are weird. Can't use hover...
49
49
 
50
50
  if (withPointerEvents) {
51
51
  _dom.fireEvent.pointerOver(option);
@@ -80,12 +80,10 @@ function selectOptionsBase(newValue, select, values, {
80
80
  }
81
81
  }
82
82
  } else if (selectedOptions.length === 1) {
83
- const withPointerEvents = skipPointerEventsCheck ? true : (0, _utils.hasPointerEvents)(select); // the click to open the select options
83
+ const withPointerEvents = this[_setup.Config].skipPointerEventsCheck ? true : (0, _utils.hasPointerEvents)(select); // the click to open the select options
84
84
 
85
85
  if (withPointerEvents) {
86
- this.click(select, {
87
- skipPointerEventsCheck: true
88
- });
86
+ await this.click(select);
89
87
  } else {
90
88
  (0, _utils.focus)(select);
91
89
  }
@@ -113,17 +111,10 @@ function selectOptionsBase(newValue, select, values, {
113
111
  throw (0, _dom.getConfig)().getElementError(`Cannot select multiple options on a non-multiple select`, select);
114
112
  }
115
113
  } else if (select.getAttribute('role') === 'listbox') {
116
- selectedOptions.forEach(option => {
117
- this.hover(option, {
118
- skipPointerEventsCheck
119
- });
120
- this.click(option, {
121
- skipPointerEventsCheck
122
- });
123
- this.unhover(option, {
124
- skipPointerEventsCheck
125
- });
126
- });
114
+ for (const option of selectedOptions) {
115
+ await this.click(option);
116
+ await this.unhover(option);
117
+ }
127
118
  } else {
128
119
  throw (0, _dom.getConfig)().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
129
120
  }