@testing-library/user-event 14.2.1 → 14.2.4

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.
package/dist/index.cjs CHANGED
@@ -1,25 +1,8 @@
1
1
  "use strict";
2
2
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __spreadValues = (a, b) => {
12
- for (var prop in b || (b = {}))
13
- if (__hasOwnProp.call(b, prop))
14
- __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols)
16
- for (var prop of __getOwnPropSymbols(b)) {
17
- if (__propIsEnum.call(b, prop))
18
- __defNormalProp(a, prop, b[prop]);
19
- }
20
- return a;
21
- };
22
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
6
  var __export = (target, all) => {
24
7
  for (var name in all)
25
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -86,8 +69,9 @@ function readBlobText(blob, FileReader) {
86
69
  }
87
70
 
88
71
  // src/utils/dataTransfer/FileList.ts
89
- function createFileList(files) {
90
- const list = __spreadProps(__spreadValues({}, files), {
72
+ function createFileList(window, files) {
73
+ const list = {
74
+ ...files,
91
75
  length: files.length,
92
76
  item: (index) => list[index],
93
77
  [Symbol.iterator]: function* nextFile() {
@@ -95,9 +79,9 @@ function createFileList(files) {
95
79
  yield list[i];
96
80
  }
97
81
  }
98
- });
99
- list.constructor = FileList;
100
- Object.setPrototypeOf(list, FileList.prototype);
82
+ };
83
+ list.constructor = window.FileList;
84
+ Object.setPrototypeOf(list, window.FileList.prototype);
101
85
  Object.freeze(list);
102
86
  return list;
103
87
  }
@@ -149,56 +133,58 @@ function getTypeMatcher(type3, exact) {
149
133
  return exact ? item.type === (isGroup ? group : type3) : isGroup ? item.type.startsWith(`${group}/`) : item.type === group;
150
134
  };
151
135
  }
152
- var DataTransferStub = class {
153
- constructor() {
154
- this.dropEffect = "none";
155
- this.effectAllowed = "uninitialized";
156
- this.items = new DataTransferItemListStub();
157
- this.files = createFileList([]);
158
- }
159
- getData(format) {
160
- var _a;
161
- const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
162
- let text = "";
163
- match == null ? void 0 : match.getAsString((t) => {
164
- text = t;
165
- });
166
- return text;
167
- }
168
- setData(format, data) {
169
- const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
170
- const item = new DataTransferItemStub(data, format);
171
- if (matchIndex >= 0) {
172
- this.items.splice(matchIndex, 1, item);
173
- } else {
174
- this.items.push(item);
136
+ function createDataTransferStub(window) {
137
+ return new class DataTransferStub {
138
+ constructor() {
139
+ this.dropEffect = "none";
140
+ this.effectAllowed = "uninitialized";
141
+ this.items = new DataTransferItemListStub();
142
+ this.files = createFileList(window, []);
175
143
  }
176
- }
177
- clearData(format) {
178
- if (format) {
144
+ getData(format) {
145
+ var _a;
146
+ const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
147
+ let text = "";
148
+ match == null ? void 0 : match.getAsString((t) => {
149
+ text = t;
150
+ });
151
+ return text;
152
+ }
153
+ setData(format, data) {
179
154
  const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
155
+ const item = new DataTransferItemStub(data, format);
180
156
  if (matchIndex >= 0) {
181
- this.items.remove(matchIndex);
157
+ this.items.splice(matchIndex, 1, item);
158
+ } else {
159
+ this.items.push(item);
182
160
  }
183
- } else {
184
- this.items.clear();
185
161
  }
186
- }
187
- get types() {
188
- const t = [];
189
- if (this.files.length) {
190
- t.push("Files");
162
+ clearData(format) {
163
+ if (format) {
164
+ const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
165
+ if (matchIndex >= 0) {
166
+ this.items.remove(matchIndex);
167
+ }
168
+ } else {
169
+ this.items.clear();
170
+ }
191
171
  }
192
- this.items.forEach((i) => t.push(i.type));
193
- Object.freeze(t);
194
- return t;
195
- }
196
- setDragImage() {
197
- }
198
- };
172
+ get types() {
173
+ const t = [];
174
+ if (this.files.length) {
175
+ t.push("Files");
176
+ }
177
+ this.items.forEach((i) => t.push(i.type));
178
+ Object.freeze(t);
179
+ return t;
180
+ }
181
+ setDragImage() {
182
+ }
183
+ }();
184
+ }
199
185
  function createDataTransfer(window, files = []) {
200
- const dt = typeof window.DataTransfer === "undefined" ? new DataTransferStub() : new window.DataTransfer();
201
- Object.defineProperty(dt, "files", { get: () => createFileList(files) });
186
+ const dt = typeof window.DataTransfer === "undefined" ? createDataTransferStub(window) : new window.DataTransfer();
187
+ Object.defineProperty(dt, "files", { get: () => createFileList(window, files) });
202
188
  return dt;
203
189
  }
204
190
  function getBlobFromDataTransferItem(window, item) {
@@ -610,17 +596,30 @@ function setFiles(el, files) {
610
596
  const prototypeDescriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(el));
611
597
  function restore() {
612
598
  Object.defineProperties(el, {
613
- files: __spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files),
614
- value: __spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value),
615
- type: __spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type)
599
+ files: {
600
+ ...prototypeDescriptors.files,
601
+ ...objectDescriptors.files
602
+ },
603
+ value: {
604
+ ...prototypeDescriptors.value,
605
+ ...objectDescriptors.value
606
+ },
607
+ type: {
608
+ ...prototypeDescriptors.type,
609
+ ...objectDescriptors.type
610
+ }
616
611
  });
617
612
  }
618
613
  el[fakeFiles] = { restore };
619
614
  Object.defineProperties(el, {
620
- files: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.files), objectDescriptors.files), {
615
+ files: {
616
+ ...prototypeDescriptors.files,
617
+ ...objectDescriptors.files,
621
618
  get: () => files
622
- }),
623
- value: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.value), objectDescriptors.value), {
619
+ },
620
+ value: {
621
+ ...prototypeDescriptors.value,
622
+ ...objectDescriptors.value,
624
623
  get: () => files.length ? `C:\\fakepath\\${files[0].name}` : "",
625
624
  set(v) {
626
625
  var _a2;
@@ -630,15 +629,17 @@ function setFiles(el, files) {
630
629
  (_a2 = objectDescriptors.value.set) == null ? void 0 : _a2.call(el, v);
631
630
  }
632
631
  }
633
- }),
634
- type: __spreadProps(__spreadValues(__spreadValues({}, prototypeDescriptors.type), objectDescriptors.type), {
632
+ },
633
+ type: {
634
+ ...prototypeDescriptors.type,
635
+ ...objectDescriptors.type,
635
636
  set(v) {
636
637
  if (v !== "file") {
637
638
  restore();
638
639
  el.type = v;
639
640
  }
640
641
  }
641
- })
642
+ }
642
643
  });
643
644
  }
644
645
 
@@ -1116,9 +1117,10 @@ function readNextDescriptor(text, context) {
1116
1117
  pos += startBracket.length;
1117
1118
  const isEscapedChar = new RegExp(`^\\${startBracket}{2}`).test(text);
1118
1119
  const type3 = isEscapedChar ? "" : startBracket;
1119
- return __spreadValues({
1120
- type: type3
1121
- }, type3 === "" ? readPrintableChar(text, pos, context) : readTag(text, pos, type3, context));
1120
+ return {
1121
+ type: type3,
1122
+ ...type3 === "" ? readPrintableChar(text, pos, context) : readTag(text, pos, type3, context)
1123
+ };
1122
1124
  }
1123
1125
  function readPrintableChar(text, pos, context) {
1124
1126
  const descriptor = text[pos];
@@ -1319,9 +1321,10 @@ var defaultOptionsDirect = {
1319
1321
  writeToClipboard: false,
1320
1322
  advanceTimers: () => Promise.resolve()
1321
1323
  };
1322
- var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect), {
1324
+ var defaultOptionsSetup = {
1325
+ ...defaultOptionsDirect,
1323
1326
  writeToClipboard: true
1324
- });
1327
+ };
1325
1328
 
1326
1329
  // src/utils/pointer/cssPointerEvents.ts
1327
1330
  function hasPointerEvents(element) {
@@ -1440,12 +1443,13 @@ var import_dom2 = require("@testing-library/dom");
1440
1443
 
1441
1444
  // src/event/eventMap.ts
1442
1445
  var import_event_map = require("@testing-library/dom/dist/event-map.js");
1443
- var eventMap = __spreadProps(__spreadValues({}, import_event_map.eventMap), {
1446
+ var eventMap = {
1447
+ ...import_event_map.eventMap,
1444
1448
  beforeInput: {
1445
1449
  EventType: "InputEvent",
1446
1450
  defaultInit: { bubbles: true, cancelable: true, composed: true }
1447
1451
  }
1448
- });
1452
+ };
1449
1453
  var eventMapKeys = Object.fromEntries(Object.keys(eventMap).map((k) => [k.toLowerCase(), k]));
1450
1454
 
1451
1455
  // src/event/eventTypes.ts
@@ -1719,7 +1723,10 @@ function dispatchEvent(config, target, event, preventDefault = false) {
1719
1723
  // src/event/index.ts
1720
1724
  function dispatchUIEvent(config, target, type3, init, preventDefault = false) {
1721
1725
  if (isMouseEvent(type3) || isKeyboardEvent(type3)) {
1722
- init = __spreadValues(__spreadValues({}, init), getUIEventModifiers(config.keyboardState));
1726
+ init = {
1727
+ ...init,
1728
+ ...getUIEventModifiers(config.keyboardState)
1729
+ };
1723
1730
  }
1724
1731
  const event = createEvent(type3, target, init);
1725
1732
  return dispatchEvent(config, target, event, preventDefault);
@@ -1739,7 +1746,7 @@ function prepareInterceptor(element, propName, interceptorImpl) {
1739
1746
  }
1740
1747
  function intercept(...args) {
1741
1748
  const {
1742
- applyNative = true,
1749
+ applyNative = false,
1743
1750
  realArgs,
1744
1751
  then
1745
1752
  } = interceptorImpl.call(this, ...args);
@@ -1753,21 +1760,23 @@ function prepareInterceptor(element, propName, interceptorImpl) {
1753
1760
  }
1754
1761
  ;
1755
1762
  intercept[Interceptor] = Interceptor;
1756
- Object.defineProperty(element, propName, __spreadProps(__spreadValues({}, objectDescriptor != null ? objectDescriptor : prototypeDescriptor), {
1763
+ Object.defineProperty(element, propName, {
1764
+ ...objectDescriptor != null ? objectDescriptor : prototypeDescriptor,
1757
1765
  [target]: intercept
1758
- }));
1766
+ });
1759
1767
  }
1760
1768
 
1761
1769
  // src/document/selection.ts
1762
1770
  var UISelection = Symbol("Displayed selection in UI");
1763
1771
  function prepareSelectionInterceptor(element) {
1764
- prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
1772
+ prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, ...others) {
1765
1773
  const isUI = start && typeof start === "object" && start[UISelection];
1766
1774
  if (!isUI) {
1767
1775
  this[UISelection] = void 0;
1768
1776
  }
1769
1777
  return {
1770
- realArgs: [Number(start), end, direction]
1778
+ applyNative: !!isUI,
1779
+ realArgs: [Number(start), ...others]
1771
1780
  };
1772
1781
  });
1773
1782
  prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
@@ -1816,10 +1825,14 @@ function getUISelection(element) {
1816
1825
  anchorOffset: (_a = element.selectionStart) != null ? _a : 0,
1817
1826
  focusOffset: (_b = element.selectionEnd) != null ? _b : 0
1818
1827
  };
1819
- return __spreadProps(__spreadValues({}, sel), {
1828
+ return {
1829
+ ...sel,
1820
1830
  startOffset: Math.min(sel.anchorOffset, sel.focusOffset),
1821
1831
  endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
1822
- });
1832
+ };
1833
+ }
1834
+ function setUISelectionClean(element) {
1835
+ element[UISelection] = void 0;
1823
1836
  }
1824
1837
 
1825
1838
  // src/document/value.ts
@@ -1859,6 +1872,9 @@ function setUIValue(element, value) {
1859
1872
  function getUIValue(element) {
1860
1873
  return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
1861
1874
  }
1875
+ function setUIValueClean(element) {
1876
+ element[UIValue] = void 0;
1877
+ }
1862
1878
  function clearInitialValue(element) {
1863
1879
  element[InitialValue] = void 0;
1864
1880
  }
@@ -1866,13 +1882,14 @@ function getInitialValue(element) {
1866
1882
  return element[InitialValue];
1867
1883
  }
1868
1884
  function setPreviousValue(element, v) {
1869
- element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), { previousValue: v });
1885
+ element[TrackChanges] = { ...element[TrackChanges], previousValue: v };
1870
1886
  }
1871
1887
  function startTrackValue(element) {
1872
- element[TrackChanges] = __spreadProps(__spreadValues({}, element[TrackChanges]), {
1888
+ element[TrackChanges] = {
1889
+ ...element[TrackChanges],
1873
1890
  nextValue: String(element.value),
1874
1891
  tracked: []
1875
- });
1892
+ };
1876
1893
  }
1877
1894
  function trackOrSetValue(element, v) {
1878
1895
  var _a, _b, _c;
@@ -1896,6 +1913,19 @@ function endTrackValue(element) {
1896
1913
  return isJustReactStateUpdate;
1897
1914
  }
1898
1915
 
1916
+ // src/document/setRangeText.ts
1917
+ function prepareRangeTextInterceptor(element) {
1918
+ prepareInterceptor(element, "setRangeText", function interceptorImpl(...realArgs) {
1919
+ return {
1920
+ realArgs,
1921
+ then: () => {
1922
+ setUIValueClean(element);
1923
+ setUISelectionClean(element);
1924
+ }
1925
+ };
1926
+ });
1927
+ }
1928
+
1899
1929
  // src/document/index.ts
1900
1930
  var isPrepared = Symbol("Node prepared with document state workarounds");
1901
1931
  function prepareDocument(document) {
@@ -1934,6 +1964,7 @@ function prepareElement(el) {
1934
1964
  if ("value" in el) {
1935
1965
  prepareValueInterceptor(el);
1936
1966
  prepareSelectionInterceptor(el);
1967
+ prepareRangeTextInterceptor(el);
1937
1968
  }
1938
1969
  el[isPrepared] = isPrepared;
1939
1970
  }
@@ -2049,9 +2080,10 @@ async function keydown(keyDef, getCurrentElement, config) {
2049
2080
  }
2050
2081
  async function keypress(keyDef, getCurrentElement, config) {
2051
2082
  const element = getCurrentElement();
2052
- dispatchUIEvent(config, element, "keypress", __spreadProps(__spreadValues({}, getKeyEventProps(keyDef)), {
2083
+ dispatchUIEvent(config, element, "keypress", {
2084
+ ...getKeyEventProps(keyDef),
2053
2085
  charCode: keyDef.key === "Enter" ? 13 : String(keyDef.key).charCodeAt(0)
2054
- }));
2086
+ });
2055
2087
  }
2056
2088
  async function keyup(keyDef, getCurrentElement, config, unprevented) {
2057
2089
  const element = getCurrentElement();
@@ -2153,7 +2185,9 @@ function firePointerEvent(config, target, type3, {
2153
2185
  isPrimary,
2154
2186
  clickCount
2155
2187
  }) {
2156
- const init = __spreadValues({}, coords);
2188
+ const init = {
2189
+ ...coords
2190
+ };
2157
2191
  if (type3 === "click" || type3.startsWith("pointer")) {
2158
2192
  init.pointerId = pointerId;
2159
2193
  init.pointerType = pointerType;
@@ -2239,10 +2273,11 @@ async function pointerMove(config, { pointerName = "mouse", target, coords, node
2239
2273
  }
2240
2274
  setLevelRef(config, 2 /* Trigger */);
2241
2275
  assertPointerEvents(config, target);
2242
- pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
2276
+ pointerState.position[pointerName] = {
2277
+ ...pointerState.position[pointerName],
2243
2278
  target,
2244
2279
  coords
2245
- });
2280
+ };
2246
2281
  if (prevTarget !== target) {
2247
2282
  if (!prevTarget || !isDescendantOrSelf(prevTarget, target)) {
2248
2283
  fireEnter(target, coords);
@@ -2328,12 +2363,13 @@ function down(config, pointerName, { keyDef, node, offset, target, coords }, tar
2328
2363
  const { pointerState } = config;
2329
2364
  const { name, pointerType, button } = keyDef;
2330
2365
  const pointerId = pointerType === "mouse" ? 1 : getNextPointerId(pointerState);
2331
- pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
2366
+ pointerState.position[pointerName] = {
2367
+ ...pointerState.position[pointerName],
2332
2368
  pointerId,
2333
2369
  pointerType,
2334
2370
  target,
2335
2371
  coords
2336
- });
2372
+ };
2337
2373
  let isMultiTouch = false;
2338
2374
  let isPrimary = true;
2339
2375
  if (pointerType !== "mouse") {
@@ -2410,10 +2446,11 @@ function up(config, pointerName, {
2410
2446
  pointerState.pressed = pointerState.pressed.filter((p) => p !== pressed);
2411
2447
  const { isMultiTouch, isPrimary, pointerId, clickCount } = pressed;
2412
2448
  let { unpreventedDefault } = pressed;
2413
- pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
2449
+ pointerState.position[pointerName] = {
2450
+ ...pointerState.position[pointerName],
2414
2451
  target,
2415
2452
  coords
2416
- });
2453
+ };
2417
2454
  if (pointerType !== "mouse" || !pointerState.pressed.filter((p) => p.keyDef.pointerType === pointerType).length) {
2418
2455
  fire("pointerup");
2419
2456
  }
@@ -2534,7 +2571,7 @@ async function pointerAction(config, actions) {
2534
2571
  const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
2535
2572
  const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
2536
2573
  const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
2537
- await ("keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords })));
2574
+ await ("keyDef" in action ? pointerPress(config, { ...action, target, coords }) : pointerMove(config, { ...action, target, coords }));
2538
2575
  if (i < actions.length - 1) {
2539
2576
  await wait(config);
2540
2577
  }
@@ -2556,7 +2593,10 @@ async function pointer(input2) {
2556
2593
  if (typeof actionInput === "string") {
2557
2594
  actions.push(...parseKeyDef2(pointerMap, actionInput));
2558
2595
  } else if ("keys" in actionInput) {
2559
- actions.push(...parseKeyDef2(pointerMap, actionInput.keys).map((i) => __spreadValues(__spreadValues({}, actionInput), i)));
2596
+ actions.push(...parseKeyDef2(pointerMap, actionInput.keys).map((i) => ({
2597
+ ...actionInput,
2598
+ ...i
2599
+ })));
2560
2600
  } else {
2561
2601
  actions.push(actionInput);
2562
2602
  }
@@ -2841,7 +2881,7 @@ async function upload(element, fileOrFiles) {
2841
2881
  })) {
2842
2882
  return;
2843
2883
  }
2844
- setFiles(input2, createFileList(files));
2884
+ setFiles(input2, createFileList(getWindow(element), files));
2845
2885
  this.dispatchUIEvent(input2, "input");
2846
2886
  this.dispatchUIEvent(input2, "change");
2847
2887
  };
@@ -2877,11 +2917,13 @@ function createConfig(options = {}, defaults = defaultOptionsSetup, node) {
2877
2917
  keyboardState = createKeyboardState(),
2878
2918
  pointerState = createPointerState(document)
2879
2919
  } = options;
2880
- return __spreadProps(__spreadValues(__spreadValues({}, defaults), options), {
2920
+ return {
2921
+ ...defaults,
2922
+ ...options,
2881
2923
  document,
2882
2924
  keyboardState,
2883
2925
  pointerState
2884
- });
2926
+ };
2885
2927
  }
2886
2928
  function setupMain(options = {}) {
2887
2929
  var _a;
@@ -2900,7 +2942,10 @@ function setupDirect(options = {}, node) {
2900
2942
  };
2901
2943
  }
2902
2944
  function setupSub(options) {
2903
- return doSetup(__spreadValues(__spreadValues({}, this[Config]), options));
2945
+ return doSetup({
2946
+ ...this[Config],
2947
+ ...options
2948
+ });
2904
2949
  }
2905
2950
  function wrapAndBindImpl(instance, impl) {
2906
2951
  function method(...args) {
@@ -2914,16 +2959,18 @@ function wrapAndBindImpl(instance, impl) {
2914
2959
  return method;
2915
2960
  }
2916
2961
  function doSetup(config) {
2917
- const instance = __spreadValues({
2962
+ const instance = {
2918
2963
  [Config]: config,
2919
- dispatchUIEvent: bindDispatchUIEvent(config)
2920
- }, api_exports);
2921
- return __spreadProps(__spreadValues({}, Object.fromEntries(Object.entries(api_exports).map(([name, api]) => [
2922
- name,
2923
- wrapAndBindImpl(instance, api)
2924
- ]))), {
2964
+ dispatchUIEvent: bindDispatchUIEvent(config),
2965
+ ...api_exports
2966
+ };
2967
+ return {
2968
+ ...Object.fromEntries(Object.entries(api_exports).map(([name, api]) => [
2969
+ name,
2970
+ wrapAndBindImpl(instance, api)
2971
+ ])),
2925
2972
  setup: setupSub.bind(instance)
2926
- });
2973
+ };
2927
2974
  }
2928
2975
  function getDocument(options, node, defaults) {
2929
2976
  var _a, _b;
@@ -3004,6 +3051,7 @@ function tab2(options = {}) {
3004
3051
  }
3005
3052
 
3006
3053
  // src/setup/index.ts
3007
- var userEvent = __spreadProps(__spreadValues({}, directApi_exports), {
3054
+ var userEvent = {
3055
+ ...directApi_exports,
3008
3056
  setup: setupMain
3009
- });
3057
+ };
package/dist/index.mjs CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __defProp = Object.defineProperty;
3
2
  var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -88,7 +87,7 @@ function readBlobText(blob, FileReader) {
88
87
  }
89
88
 
90
89
  // src/utils/dataTransfer/FileList.ts
91
- function createFileList(files) {
90
+ function createFileList(window, files) {
92
91
  const list = __spreadProps(__spreadValues({}, files), {
93
92
  length: files.length,
94
93
  item: (index) => list[index],
@@ -98,8 +97,8 @@ function createFileList(files) {
98
97
  }
99
98
  }
100
99
  });
101
- list.constructor = FileList;
102
- Object.setPrototypeOf(list, FileList.prototype);
100
+ list.constructor = window.FileList;
101
+ Object.setPrototypeOf(list, window.FileList.prototype);
103
102
  Object.freeze(list);
104
103
  return list;
105
104
  }
@@ -151,56 +150,58 @@ function getTypeMatcher(type3, exact) {
151
150
  return exact ? item.type === (isGroup ? group : type3) : isGroup ? item.type.startsWith(`${group}/`) : item.type === group;
152
151
  };
153
152
  }
154
- var DataTransferStub = class {
155
- constructor() {
156
- this.dropEffect = "none";
157
- this.effectAllowed = "uninitialized";
158
- this.items = new DataTransferItemListStub();
159
- this.files = createFileList([]);
160
- }
161
- getData(format) {
162
- var _a;
163
- const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
164
- let text = "";
165
- match == null ? void 0 : match.getAsString((t) => {
166
- text = t;
167
- });
168
- return text;
169
- }
170
- setData(format, data) {
171
- const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
172
- const item = new DataTransferItemStub(data, format);
173
- if (matchIndex >= 0) {
174
- this.items.splice(matchIndex, 1, item);
175
- } else {
176
- this.items.push(item);
153
+ function createDataTransferStub(window) {
154
+ return new class DataTransferStub {
155
+ constructor() {
156
+ this.dropEffect = "none";
157
+ this.effectAllowed = "uninitialized";
158
+ this.items = new DataTransferItemListStub();
159
+ this.files = createFileList(window, []);
177
160
  }
178
- }
179
- clearData(format) {
180
- if (format) {
161
+ getData(format) {
162
+ var _a;
163
+ const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
164
+ let text = "";
165
+ match == null ? void 0 : match.getAsString((t) => {
166
+ text = t;
167
+ });
168
+ return text;
169
+ }
170
+ setData(format, data) {
181
171
  const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
172
+ const item = new DataTransferItemStub(data, format);
182
173
  if (matchIndex >= 0) {
183
- this.items.remove(matchIndex);
174
+ this.items.splice(matchIndex, 1, item);
175
+ } else {
176
+ this.items.push(item);
184
177
  }
185
- } else {
186
- this.items.clear();
187
178
  }
188
- }
189
- get types() {
190
- const t = [];
191
- if (this.files.length) {
192
- t.push("Files");
179
+ clearData(format) {
180
+ if (format) {
181
+ const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
182
+ if (matchIndex >= 0) {
183
+ this.items.remove(matchIndex);
184
+ }
185
+ } else {
186
+ this.items.clear();
187
+ }
193
188
  }
194
- this.items.forEach((i) => t.push(i.type));
195
- Object.freeze(t);
196
- return t;
197
- }
198
- setDragImage() {
199
- }
200
- };
189
+ get types() {
190
+ const t = [];
191
+ if (this.files.length) {
192
+ t.push("Files");
193
+ }
194
+ this.items.forEach((i) => t.push(i.type));
195
+ Object.freeze(t);
196
+ return t;
197
+ }
198
+ setDragImage() {
199
+ }
200
+ }();
201
+ }
201
202
  function createDataTransfer(window, files = []) {
202
- const dt = typeof window.DataTransfer === "undefined" ? new DataTransferStub() : new window.DataTransfer();
203
- Object.defineProperty(dt, "files", { get: () => createFileList(files) });
203
+ const dt = typeof window.DataTransfer === "undefined" ? createDataTransferStub(window) : new window.DataTransfer();
204
+ Object.defineProperty(dt, "files", { get: () => createFileList(window, files) });
204
205
  return dt;
205
206
  }
206
207
  function getBlobFromDataTransferItem(window, item) {
@@ -1755,7 +1756,7 @@ function prepareInterceptor(element, propName, interceptorImpl) {
1755
1756
  }
1756
1757
  function intercept(...args) {
1757
1758
  const {
1758
- applyNative = true,
1759
+ applyNative = false,
1759
1760
  realArgs,
1760
1761
  then
1761
1762
  } = interceptorImpl.call(this, ...args);
@@ -1777,13 +1778,14 @@ function prepareInterceptor(element, propName, interceptorImpl) {
1777
1778
  // src/document/selection.ts
1778
1779
  var UISelection = Symbol("Displayed selection in UI");
1779
1780
  function prepareSelectionInterceptor(element) {
1780
- prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
1781
+ prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, ...others) {
1781
1782
  const isUI = start && typeof start === "object" && start[UISelection];
1782
1783
  if (!isUI) {
1783
1784
  this[UISelection] = void 0;
1784
1785
  }
1785
1786
  return {
1786
- realArgs: [Number(start), end, direction]
1787
+ applyNative: !!isUI,
1788
+ realArgs: [Number(start), ...others]
1787
1789
  };
1788
1790
  });
1789
1791
  prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
@@ -1837,6 +1839,9 @@ function getUISelection(element) {
1837
1839
  endOffset: Math.max(sel.anchorOffset, sel.focusOffset)
1838
1840
  });
1839
1841
  }
1842
+ function setUISelectionClean(element) {
1843
+ element[UISelection] = void 0;
1844
+ }
1840
1845
 
1841
1846
  // src/document/value.ts
1842
1847
  var UIValue = Symbol("Displayed value in UI");
@@ -1875,6 +1880,9 @@ function setUIValue(element, value) {
1875
1880
  function getUIValue(element) {
1876
1881
  return element[UIValue] === void 0 ? element.value : String(element[UIValue]);
1877
1882
  }
1883
+ function setUIValueClean(element) {
1884
+ element[UIValue] = void 0;
1885
+ }
1878
1886
  function clearInitialValue(element) {
1879
1887
  element[InitialValue] = void 0;
1880
1888
  }
@@ -1912,6 +1920,19 @@ function endTrackValue(element) {
1912
1920
  return isJustReactStateUpdate;
1913
1921
  }
1914
1922
 
1923
+ // src/document/setRangeText.ts
1924
+ function prepareRangeTextInterceptor(element) {
1925
+ prepareInterceptor(element, "setRangeText", function interceptorImpl(...realArgs) {
1926
+ return {
1927
+ realArgs,
1928
+ then: () => {
1929
+ setUIValueClean(element);
1930
+ setUISelectionClean(element);
1931
+ }
1932
+ };
1933
+ });
1934
+ }
1935
+
1915
1936
  // src/document/index.ts
1916
1937
  var isPrepared = Symbol("Node prepared with document state workarounds");
1917
1938
  function prepareDocument(document) {
@@ -1950,6 +1971,7 @@ function prepareElement(el) {
1950
1971
  if ("value" in el) {
1951
1972
  prepareValueInterceptor(el);
1952
1973
  prepareSelectionInterceptor(el);
1974
+ prepareRangeTextInterceptor(el);
1953
1975
  }
1954
1976
  el[isPrepared] = isPrepared;
1955
1977
  }
@@ -2908,7 +2930,7 @@ function upload(element, fileOrFiles) {
2908
2930
  })) {
2909
2931
  return;
2910
2932
  }
2911
- setFiles(input2, createFileList(files));
2933
+ setFiles(input2, createFileList(getWindow(element), files));
2912
2934
  this.dispatchUIEvent(input2, "input");
2913
2935
  this.dispatchUIEvent(input2, "change");
2914
2936
  };
@@ -23,4 +23,6 @@ export declare function getUISelection(element: HTMLInputElement | HTMLTextAreaE
23
23
  anchorOffset: number;
24
24
  focusOffset: number;
25
25
  };
26
+ /** Flag the IDL selection as clean. This does not change the selection. */
27
+ export declare function setUISelectionClean(element: HTMLInputElement | HTMLTextAreaElement): void;
26
28
  export {};
@@ -0,0 +1 @@
1
+ export declare function prepareRangeTextInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void;
@@ -15,6 +15,8 @@ declare global {
15
15
  export declare function prepareValueInterceptor(element: HTMLInputElement): void;
16
16
  export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaElement, value: string): void;
17
17
  export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string;
18
+ /** Flag the IDL value as clean. This does not change the value.*/
19
+ export declare function setUIValueClean(element: HTMLInputElement | HTMLTextAreaElement): void;
18
20
  export declare function clearInitialValue(element: HTMLInputElement | HTMLTextAreaElement): void;
19
21
  export declare function getInitialValue(element: HTMLInputElement | HTMLTextAreaElement): string | undefined;
20
22
  export declare function startTrackValue(element: HTMLInputElement | HTMLTextAreaElement): void;
@@ -1 +1 @@
1
- export declare function createFileList(files: File[]): FileList;
1
+ export declare function createFileList(window: Window & typeof globalThis, files: File[]): FileList;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.2.1",
3
+ "version": "14.2.4",
4
4
  "description": "Fire events the same way the user does",
5
5
  "keywords": [
6
6
  "react-testing-library",