@testing-library/user-event 14.2.2 → 14.2.5

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
@@ -69,7 +69,7 @@ function readBlobText(blob, FileReader) {
69
69
  }
70
70
 
71
71
  // src/utils/dataTransfer/FileList.ts
72
- function createFileList(files) {
72
+ function createFileList(window, files) {
73
73
  const list = {
74
74
  ...files,
75
75
  length: files.length,
@@ -80,8 +80,8 @@ function createFileList(files) {
80
80
  }
81
81
  }
82
82
  };
83
- list.constructor = FileList;
84
- Object.setPrototypeOf(list, FileList.prototype);
83
+ list.constructor = window.FileList;
84
+ Object.setPrototypeOf(list, window.FileList.prototype);
85
85
  Object.freeze(list);
86
86
  return list;
87
87
  }
@@ -133,56 +133,58 @@ function getTypeMatcher(type3, exact) {
133
133
  return exact ? item.type === (isGroup ? group : type3) : isGroup ? item.type.startsWith(`${group}/`) : item.type === group;
134
134
  };
135
135
  }
136
- var DataTransferStub = class {
137
- constructor() {
138
- this.dropEffect = "none";
139
- this.effectAllowed = "uninitialized";
140
- this.items = new DataTransferItemListStub();
141
- this.files = createFileList([]);
142
- }
143
- getData(format) {
144
- var _a;
145
- const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
146
- let text = "";
147
- match == null ? void 0 : match.getAsString((t) => {
148
- text = t;
149
- });
150
- return text;
151
- }
152
- setData(format, data) {
153
- const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
154
- const item = new DataTransferItemStub(data, format);
155
- if (matchIndex >= 0) {
156
- this.items.splice(matchIndex, 1, item);
157
- } else {
158
- 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, []);
159
143
  }
160
- }
161
- clearData(format) {
162
- 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) {
163
154
  const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
155
+ const item = new DataTransferItemStub(data, format);
164
156
  if (matchIndex >= 0) {
165
- this.items.remove(matchIndex);
157
+ this.items.splice(matchIndex, 1, item);
158
+ } else {
159
+ this.items.push(item);
166
160
  }
167
- } else {
168
- this.items.clear();
169
161
  }
170
- }
171
- get types() {
172
- const t = [];
173
- if (this.files.length) {
174
- 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
+ }
175
171
  }
176
- this.items.forEach((i) => t.push(i.type));
177
- Object.freeze(t);
178
- return t;
179
- }
180
- setDragImage() {
181
- }
182
- };
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
+ }
183
185
  function createDataTransfer(window, files = []) {
184
- const dt = typeof window.DataTransfer === "undefined" ? new DataTransferStub() : new window.DataTransfer();
185
- 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) });
186
188
  return dt;
187
189
  }
188
190
  function getBlobFromDataTransferItem(window, item) {
@@ -1740,11 +1742,11 @@ function prepareInterceptor(element, propName, interceptorImpl) {
1740
1742
  const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
1741
1743
  const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
1742
1744
  if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
1743
- return;
1745
+ throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
1744
1746
  }
1745
1747
  function intercept(...args) {
1746
1748
  const {
1747
- applyNative = true,
1749
+ applyNative = false,
1748
1750
  realArgs,
1749
1751
  then
1750
1752
  } = interceptorImpl.call(this, ...args);
@@ -1767,13 +1769,14 @@ function prepareInterceptor(element, propName, interceptorImpl) {
1767
1769
  // src/document/selection.ts
1768
1770
  var UISelection = Symbol("Displayed selection in UI");
1769
1771
  function prepareSelectionInterceptor(element) {
1770
- prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
1772
+ prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, ...others) {
1771
1773
  const isUI = start && typeof start === "object" && start[UISelection];
1772
1774
  if (!isUI) {
1773
1775
  this[UISelection] = void 0;
1774
1776
  }
1775
1777
  return {
1776
- realArgs: [Number(start), end, direction]
1778
+ applyNative: !!isUI,
1779
+ realArgs: [Number(start), ...others]
1777
1780
  };
1778
1781
  });
1779
1782
  prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
@@ -1958,7 +1961,7 @@ function prepareElement(el) {
1958
1961
  if (el[isPrepared]) {
1959
1962
  return;
1960
1963
  }
1961
- if ("value" in el) {
1964
+ if (isElementType(el, ["input", "textarea"])) {
1962
1965
  prepareValueInterceptor(el);
1963
1966
  prepareSelectionInterceptor(el);
1964
1967
  prepareRangeTextInterceptor(el);
@@ -2878,7 +2881,7 @@ async function upload(element, fileOrFiles) {
2878
2881
  })) {
2879
2882
  return;
2880
2883
  }
2881
- setFiles(input2, createFileList(files));
2884
+ setFiles(input2, createFileList(getWindow(element), files));
2882
2885
  this.dispatchUIEvent(input2, "input");
2883
2886
  this.dispatchUIEvent(input2, "change");
2884
2887
  };
package/dist/index.mjs CHANGED
@@ -87,7 +87,7 @@ function readBlobText(blob, FileReader) {
87
87
  }
88
88
 
89
89
  // src/utils/dataTransfer/FileList.ts
90
- function createFileList(files) {
90
+ function createFileList(window, files) {
91
91
  const list = __spreadProps(__spreadValues({}, files), {
92
92
  length: files.length,
93
93
  item: (index) => list[index],
@@ -97,8 +97,8 @@ function createFileList(files) {
97
97
  }
98
98
  }
99
99
  });
100
- list.constructor = FileList;
101
- Object.setPrototypeOf(list, FileList.prototype);
100
+ list.constructor = window.FileList;
101
+ Object.setPrototypeOf(list, window.FileList.prototype);
102
102
  Object.freeze(list);
103
103
  return list;
104
104
  }
@@ -150,56 +150,58 @@ function getTypeMatcher(type3, exact) {
150
150
  return exact ? item.type === (isGroup ? group : type3) : isGroup ? item.type.startsWith(`${group}/`) : item.type === group;
151
151
  };
152
152
  }
153
- var DataTransferStub = class {
154
- constructor() {
155
- this.dropEffect = "none";
156
- this.effectAllowed = "uninitialized";
157
- this.items = new DataTransferItemListStub();
158
- this.files = createFileList([]);
159
- }
160
- getData(format) {
161
- var _a;
162
- const match = (_a = this.items.find(getTypeMatcher(format, true))) != null ? _a : this.items.find(getTypeMatcher(format, false));
163
- let text = "";
164
- match == null ? void 0 : match.getAsString((t) => {
165
- text = t;
166
- });
167
- return text;
168
- }
169
- setData(format, data) {
170
- const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
171
- const item = new DataTransferItemStub(data, format);
172
- if (matchIndex >= 0) {
173
- this.items.splice(matchIndex, 1, item);
174
- } else {
175
- 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, []);
176
160
  }
177
- }
178
- clearData(format) {
179
- 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) {
180
171
  const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
172
+ const item = new DataTransferItemStub(data, format);
181
173
  if (matchIndex >= 0) {
182
- this.items.remove(matchIndex);
174
+ this.items.splice(matchIndex, 1, item);
175
+ } else {
176
+ this.items.push(item);
183
177
  }
184
- } else {
185
- this.items.clear();
186
178
  }
187
- }
188
- get types() {
189
- const t = [];
190
- if (this.files.length) {
191
- 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
+ }
192
188
  }
193
- this.items.forEach((i) => t.push(i.type));
194
- Object.freeze(t);
195
- return t;
196
- }
197
- setDragImage() {
198
- }
199
- };
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
+ }
200
202
  function createDataTransfer(window, files = []) {
201
- const dt = typeof window.DataTransfer === "undefined" ? new DataTransferStub() : new window.DataTransfer();
202
- 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) });
203
205
  return dt;
204
206
  }
205
207
  function getBlobFromDataTransferItem(window, item) {
@@ -1750,11 +1752,11 @@ function prepareInterceptor(element, propName, interceptorImpl) {
1750
1752
  const objectDescriptor = Object.getOwnPropertyDescriptor(element, propName);
1751
1753
  const target = (prototypeDescriptor == null ? void 0 : prototypeDescriptor.set) ? "set" : "value";
1752
1754
  if (typeof (prototypeDescriptor == null ? void 0 : prototypeDescriptor[target]) !== "function" || prototypeDescriptor[target][Interceptor]) {
1753
- return;
1755
+ throw new Error(`Element ${element.tagName} does not implement "${String(propName)}".`);
1754
1756
  }
1755
1757
  function intercept(...args) {
1756
1758
  const {
1757
- applyNative = true,
1759
+ applyNative = false,
1758
1760
  realArgs,
1759
1761
  then
1760
1762
  } = interceptorImpl.call(this, ...args);
@@ -1776,13 +1778,14 @@ function prepareInterceptor(element, propName, interceptorImpl) {
1776
1778
  // src/document/selection.ts
1777
1779
  var UISelection = Symbol("Displayed selection in UI");
1778
1780
  function prepareSelectionInterceptor(element) {
1779
- prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, end, direction = "none") {
1781
+ prepareInterceptor(element, "setSelectionRange", function interceptorImpl(start, ...others) {
1780
1782
  const isUI = start && typeof start === "object" && start[UISelection];
1781
1783
  if (!isUI) {
1782
1784
  this[UISelection] = void 0;
1783
1785
  }
1784
1786
  return {
1785
- realArgs: [Number(start), end, direction]
1787
+ applyNative: !!isUI,
1788
+ realArgs: [Number(start), ...others]
1786
1789
  };
1787
1790
  });
1788
1791
  prepareInterceptor(element, "selectionStart", function interceptorImpl(v) {
@@ -1965,7 +1968,7 @@ function prepareElement(el) {
1965
1968
  if (el[isPrepared]) {
1966
1969
  return;
1967
1970
  }
1968
- if ("value" in el) {
1971
+ if (isElementType(el, ["input", "textarea"])) {
1969
1972
  prepareValueInterceptor(el);
1970
1973
  prepareSelectionInterceptor(el);
1971
1974
  prepareRangeTextInterceptor(el);
@@ -2927,7 +2930,7 @@ function upload(element, fileOrFiles) {
2927
2930
  })) {
2928
2931
  return;
2929
2932
  }
2930
- setFiles(input2, createFileList(files));
2933
+ setFiles(input2, createFileList(getWindow(element), files));
2931
2934
  this.dispatchUIEvent(input2, "input");
2932
2935
  this.dispatchUIEvent(input2, "change");
2933
2936
  };
@@ -1,7 +1,7 @@
1
1
  declare type anyFunc = (...a: any[]) => any;
2
2
  declare type Params<Prop> = Prop extends anyFunc ? Parameters<Prop> : [Prop];
3
3
  declare type ImplReturn<Prop> = Prop extends anyFunc ? Parameters<Prop> : Prop;
4
- export declare function prepareInterceptor<ElementType extends Node, PropName extends keyof ElementType>(element: ElementType, propName: PropName, interceptorImpl: (this: ElementType, ...args: Params<ElementType[PropName]>) => {
4
+ export declare function prepareInterceptor<ElementType extends Element, PropName extends keyof ElementType>(element: ElementType, propName: PropName, interceptorImpl: (this: ElementType, ...args: Params<ElementType[PropName]>) => {
5
5
  /**
6
6
  * React tracks the changes on element properties.
7
7
  * This workaround tries to alter the DOM element without React noticing,
@@ -12,7 +12,7 @@ declare global {
12
12
  };
13
13
  }
14
14
  }
15
- export declare function prepareValueInterceptor(element: HTMLInputElement): void;
15
+ export declare function prepareValueInterceptor(element: HTMLInputElement | HTMLTextAreaElement): void;
16
16
  export declare function setUIValue(element: HTMLInputElement | HTMLTextAreaElement, value: string): void;
17
17
  export declare function getUIValue(element: HTMLInputElement | HTMLTextAreaElement): string;
18
18
  /** Flag the IDL value as clean. This does not change the value.*/
@@ -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.2",
3
+ "version": "14.2.5",
4
4
  "description": "Fire events the same way the user does",
5
5
  "keywords": [
6
6
  "react-testing-library",