@testing-library/user-event 14.6.6 → 14.6.8

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.
@@ -15,7 +15,8 @@ function prepareInterceptor(element, propName, interceptorImpl) {
15
15
  }
16
16
  function intercept(...args) {
17
17
  const { applyNative = false, realArgs, then } = interceptorImpl.call(this, ...args);
18
- const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
18
+ const sourceDescriptor = !applyNative && objectDescriptor ? objectDescriptor : prototypeDescriptor;
19
+ const realFunc = sourceDescriptor === null || sourceDescriptor === void 0 ? void 0 : sourceDescriptor[target];
19
20
  if (target === 'set') {
20
21
  realFunc.call(this, realArgs);
21
22
  } else {
@@ -31,14 +32,16 @@ function prepareInterceptor(element, propName, interceptorImpl) {
31
32
  }
32
33
  function prepareValueInterceptor(element) {
33
34
  prepareInterceptor(element, 'value', function interceptorImpl(v) {
34
- const isUI = UI.isUIValue(v);
35
+ // `value` is a [LegacyNullToEmptyString] DOMString.
36
+ const value = v === null ? '' : v;
37
+ const isUI = UI.isUIValue(value);
35
38
  if (isUI) {
36
39
  trackValue.startTrackValue(this);
37
40
  }
38
41
  return {
39
42
  applyNative: !!isUI,
40
- realArgs: sanitizeValue(this, v),
41
- then: isUI ? undefined : ()=>trackValue.trackOrSetValue(this, String(v))
43
+ realArgs: sanitizeValue(this, value),
44
+ then: isUI ? undefined : ()=>trackValue.trackOrSetValue(this, String(value))
42
45
  };
43
46
  });
44
47
  }
@@ -43,9 +43,15 @@ class DataTransferItemStub {
43
43
  }
44
44
  }
45
45
  }
46
+ function toAsciiLowercase(value) {
47
+ return value.replace(/[A-Z]/g, (char)=>char.toLowerCase());
48
+ }
46
49
  class DataTransferItemListStub extends Array {
47
50
  add(...args) {
48
- const item = new DataTransferItemStub(args[0], args[1]);
51
+ // The spec converts the type to ASCII lowercase here, but - unlike
52
+ // `setData()` - does not replace the `text` and `url` shorthands.
53
+ // https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransferitemlist-add
54
+ const item = typeof args[0] === 'string' ? new DataTransferItemStub(args[0], toAsciiLowercase(args[1])) : new DataTransferItemStub(args[0]);
49
55
  this.push(item);
50
56
  return item;
51
57
  }
@@ -56,6 +62,13 @@ class DataTransferItemListStub extends Array {
56
62
  this.splice(index, 1);
57
63
  }
58
64
  }
65
+ // The spec requires the format to be converted to ASCII lowercase
66
+ // and the shorthands `text` and `url` to be replaced with their MIME types.
67
+ // https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-setdata
68
+ function normalizeFormat(format) {
69
+ const type = toAsciiLowercase(format);
70
+ return type === 'text' ? 'text/plain' : type === 'url' ? 'text/uri-list' : type;
71
+ }
59
72
  function getTypeMatcher(type, exact) {
60
73
  const [group, sub] = type.split('/');
61
74
  const isGroup = !sub || sub === '*';
@@ -67,7 +80,8 @@ function createDataTransferStub(window) {
67
80
  return new class DataTransferStub {
68
81
  getData(format) {
69
82
  var _this_items_find;
70
- const match = (_this_items_find = this.items.find(getTypeMatcher(format, true))) !== null && _this_items_find !== void 0 ? _this_items_find : this.items.find(getTypeMatcher(format, false));
83
+ const type = normalizeFormat(format);
84
+ const match = (_this_items_find = this.items.find(getTypeMatcher(type, true))) !== null && _this_items_find !== void 0 ? _this_items_find : this.items.find(getTypeMatcher(type, false));
71
85
  let text = '';
72
86
  match === null || match === void 0 ? void 0 : match.getAsString((t)=>{
73
87
  text = t;
@@ -75,8 +89,9 @@ function createDataTransferStub(window) {
75
89
  return text;
76
90
  }
77
91
  setData(format, data) {
78
- const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
79
- const item = new DataTransferItemStub(data, format);
92
+ const type = normalizeFormat(format);
93
+ const matchIndex = this.items.findIndex(getTypeMatcher(type, true));
94
+ const item = new DataTransferItemStub(data, type);
80
95
  if (matchIndex >= 0) {
81
96
  this.items.splice(matchIndex, 1, item);
82
97
  } else {
@@ -85,7 +100,8 @@ function createDataTransferStub(window) {
85
100
  }
86
101
  clearData(format) {
87
102
  if (format) {
88
- const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
103
+ const type = normalizeFormat(format);
104
+ const matchIndex = this.items.findIndex(getTypeMatcher(type, true));
89
105
  if (matchIndex >= 0) {
90
106
  this.items.remove(matchIndex);
91
107
  }
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var isDisabled = require('../misc/isDisabled.js');
4
+ var isElementType = require('../misc/isElementType.js');
4
5
 
5
6
  function getActiveElement(document) {
6
7
  const activeElement = document.activeElement;
@@ -9,6 +10,11 @@ function getActiveElement(document) {
9
10
  if (activeElementInShadowTree) {
10
11
  return activeElementInShadowTree;
11
12
  }
13
+ } else if (activeElement && isElementType.isElementType(activeElement, 'iframe')) {
14
+ const contentDocument = activeElement.contentDocument;
15
+ if (contentDocument) {
16
+ return getActiveElement(contentDocument);
17
+ }
12
18
  }
13
19
  // Browser does not yield disabled elements as document.activeElement - jsdom does
14
20
  if (isDisabled.isDisabled(activeElement)) {
@@ -13,7 +13,8 @@ function prepareInterceptor(element, propName, interceptorImpl) {
13
13
  }
14
14
  function intercept(...args) {
15
15
  const { applyNative = false, realArgs, then } = interceptorImpl.call(this, ...args);
16
- const realFunc = (!applyNative && objectDescriptor || prototypeDescriptor)[target];
16
+ const sourceDescriptor = !applyNative && objectDescriptor ? objectDescriptor : prototypeDescriptor;
17
+ const realFunc = sourceDescriptor === null || sourceDescriptor === void 0 ? void 0 : sourceDescriptor[target];
17
18
  if (target === 'set') {
18
19
  realFunc.call(this, realArgs);
19
20
  } else {
@@ -29,14 +30,16 @@ function prepareInterceptor(element, propName, interceptorImpl) {
29
30
  }
30
31
  function prepareValueInterceptor(element) {
31
32
  prepareInterceptor(element, 'value', function interceptorImpl(v) {
32
- const isUI = isUIValue(v);
33
+ // `value` is a [LegacyNullToEmptyString] DOMString.
34
+ const value = v === null ? '' : v;
35
+ const isUI = isUIValue(value);
33
36
  if (isUI) {
34
37
  startTrackValue(this);
35
38
  }
36
39
  return {
37
40
  applyNative: !!isUI,
38
- realArgs: sanitizeValue(this, v),
39
- then: isUI ? undefined : ()=>trackOrSetValue(this, String(v))
41
+ realArgs: sanitizeValue(this, value),
42
+ then: isUI ? undefined : ()=>trackOrSetValue(this, String(value))
40
43
  };
41
44
  });
42
45
  }
@@ -41,9 +41,15 @@ class DataTransferItemStub {
41
41
  }
42
42
  }
43
43
  }
44
+ function toAsciiLowercase(value) {
45
+ return value.replace(/[A-Z]/g, (char)=>char.toLowerCase());
46
+ }
44
47
  class DataTransferItemListStub extends Array {
45
48
  add(...args) {
46
- const item = new DataTransferItemStub(args[0], args[1]);
49
+ // The spec converts the type to ASCII lowercase here, but - unlike
50
+ // `setData()` - does not replace the `text` and `url` shorthands.
51
+ // https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransferitemlist-add
52
+ const item = typeof args[0] === 'string' ? new DataTransferItemStub(args[0], toAsciiLowercase(args[1])) : new DataTransferItemStub(args[0]);
47
53
  this.push(item);
48
54
  return item;
49
55
  }
@@ -54,6 +60,13 @@ class DataTransferItemListStub extends Array {
54
60
  this.splice(index, 1);
55
61
  }
56
62
  }
63
+ // The spec requires the format to be converted to ASCII lowercase
64
+ // and the shorthands `text` and `url` to be replaced with their MIME types.
65
+ // https://html.spec.whatwg.org/multipage/dnd.html#dom-datatransfer-setdata
66
+ function normalizeFormat(format) {
67
+ const type = toAsciiLowercase(format);
68
+ return type === 'text' ? 'text/plain' : type === 'url' ? 'text/uri-list' : type;
69
+ }
57
70
  function getTypeMatcher(type, exact) {
58
71
  const [group, sub] = type.split('/');
59
72
  const isGroup = !sub || sub === '*';
@@ -65,7 +78,8 @@ function createDataTransferStub(window) {
65
78
  return new class DataTransferStub {
66
79
  getData(format) {
67
80
  var _this_items_find;
68
- const match = (_this_items_find = this.items.find(getTypeMatcher(format, true))) !== null && _this_items_find !== void 0 ? _this_items_find : this.items.find(getTypeMatcher(format, false));
81
+ const type = normalizeFormat(format);
82
+ const match = (_this_items_find = this.items.find(getTypeMatcher(type, true))) !== null && _this_items_find !== void 0 ? _this_items_find : this.items.find(getTypeMatcher(type, false));
69
83
  let text = '';
70
84
  match === null || match === void 0 ? void 0 : match.getAsString((t)=>{
71
85
  text = t;
@@ -73,8 +87,9 @@ function createDataTransferStub(window) {
73
87
  return text;
74
88
  }
75
89
  setData(format, data) {
76
- const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
77
- const item = new DataTransferItemStub(data, format);
90
+ const type = normalizeFormat(format);
91
+ const matchIndex = this.items.findIndex(getTypeMatcher(type, true));
92
+ const item = new DataTransferItemStub(data, type);
78
93
  if (matchIndex >= 0) {
79
94
  this.items.splice(matchIndex, 1, item);
80
95
  } else {
@@ -83,7 +98,8 @@ function createDataTransferStub(window) {
83
98
  }
84
99
  clearData(format) {
85
100
  if (format) {
86
- const matchIndex = this.items.findIndex(getTypeMatcher(format, true));
101
+ const type = normalizeFormat(format);
102
+ const matchIndex = this.items.findIndex(getTypeMatcher(type, true));
87
103
  if (matchIndex >= 0) {
88
104
  this.items.remove(matchIndex);
89
105
  }
@@ -1,4 +1,5 @@
1
1
  import { isDisabled } from '../misc/isDisabled.js';
2
+ import { isElementType } from '../misc/isElementType.js';
2
3
 
3
4
  function getActiveElement(document) {
4
5
  const activeElement = document.activeElement;
@@ -7,6 +8,11 @@ function getActiveElement(document) {
7
8
  if (activeElementInShadowTree) {
8
9
  return activeElementInShadowTree;
9
10
  }
11
+ } else if (activeElement && isElementType(activeElement, 'iframe')) {
12
+ const contentDocument = activeElement.contentDocument;
13
+ if (contentDocument) {
14
+ return getActiveElement(contentDocument);
15
+ }
10
16
  }
11
17
  // Browser does not yield disabled elements as document.activeElement - jsdom does
12
18
  if (isDisabled(activeElement)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.6.6",
3
+ "version": "14.6.8",
4
4
  "description": "Fire events the same way the user does",
5
5
  "keywords": [
6
6
  "react-testing-library",