@testing-library/user-event 13.1.0 → 13.1.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/README.md +10 -6
- package/dist/click.js +9 -3
- package/dist/hover.js +8 -2
- package/dist/keyboard/getNextKeyDef.js +8 -4
- package/dist/tab.js +10 -11
- package/dist/type/typeImplementation.js +4 -1
- package/dist/utils/click/isClickableInput.js +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +13 -0
- package/dist/utils/misc/isDocument.d.ts +1 -0
- package/dist/utils/misc/isDocument.js +10 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -135,7 +135,8 @@ See the
|
|
|
135
135
|
constructor documentation for more options.
|
|
136
136
|
|
|
137
137
|
Note that `click` will trigger hover events before clicking. To disable this,
|
|
138
|
-
set the `skipHover` option to `true`.
|
|
138
|
+
set the `skipHover` option to `true`. Also note that trying to click an element
|
|
139
|
+
with `pointer-events` being set to `"none"` (i.e. unclickable) will throw an error.
|
|
139
140
|
|
|
140
141
|
### `dblClick(element, eventInit, options)`
|
|
141
142
|
|
|
@@ -256,11 +257,8 @@ test('types into the input', () => {
|
|
|
256
257
|
render(
|
|
257
258
|
<>
|
|
258
259
|
<label for="time">Enter a time</label>
|
|
259
|
-
<input
|
|
260
|
-
|
|
261
|
-
id="time"
|
|
262
|
-
/>
|
|
263
|
-
</>
|
|
260
|
+
<input type="time" id="time" />
|
|
261
|
+
</>,
|
|
264
262
|
)
|
|
265
263
|
const input = screen.getByLabelText(/enter a time/i)
|
|
266
264
|
userEvent.type(input, '13:58')
|
|
@@ -769,6 +767,12 @@ Thanks goes to these people ([emoji key][emojis]):
|
|
|
769
767
|
<td align="center"><a href="https://fergusmcdonald.com"><img src="https://avatars.githubusercontent.com/u/3115675?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Fergus McDonald</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=fergusmcdonald" title="Code">💻</a></td>
|
|
770
768
|
<td align="center"><a href="https://github.com/robin-ambachtsheer"><img src="https://avatars.githubusercontent.com/u/2611873?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Robin Ambachtsheer</b></sub></a><br /><a href="https://github.com/testing-library/user-event/issues?q=author%3Arobin-ambachtsheer" title="Bug reports">🐛</a></td>
|
|
771
769
|
</tr>
|
|
770
|
+
<tr>
|
|
771
|
+
<td align="center"><a href="https://github.com/MohitPopli"><img src="https://avatars.githubusercontent.com/u/17976072?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mohit</b></sub></a><br /><a href="https://github.com/testing-library/user-event/issues?q=author%3AMohitPopli" title="Bug reports">🐛</a> <a href="https://github.com/testing-library/user-event/commits?author=MohitPopli" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=MohitPopli" title="Tests">⚠️</a></td>
|
|
772
|
+
<td align="center"><a href="https://github.com/InExtremaRes"><img src="https://avatars.githubusercontent.com/u/1635491?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Daniel Contreras</b></sub></a><br /><a href="https://github.com/testing-library/user-event/issues?q=author%3AInExtremaRes" title="Bug reports">🐛</a></td>
|
|
773
|
+
<td align="center"><a href="https://eugene.coding.blog"><img src="https://avatars.githubusercontent.com/u/13572283?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Eugene Ghanizadeh</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=loreanvictor" title="Code">💻</a></td>
|
|
774
|
+
<td align="center"><a href="https://github.com/vicrep"><img src="https://avatars.githubusercontent.com/u/11432241?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Victor Repkow</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=vicrep" title="Code">💻</a></td>
|
|
775
|
+
</tr>
|
|
772
776
|
</table>
|
|
773
777
|
|
|
774
778
|
<!-- markdownlint-restore -->
|
package/dist/click.js
CHANGED
|
@@ -103,7 +103,7 @@ function findClosest(element, callback) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
el = el.parentElement;
|
|
106
|
-
} while (el && el !==
|
|
106
|
+
} while (el && el !== element.ownerDocument.body);
|
|
107
107
|
|
|
108
108
|
return undefined;
|
|
109
109
|
}
|
|
@@ -112,7 +112,10 @@ function click(element, init, {
|
|
|
112
112
|
skipHover = false,
|
|
113
113
|
clickCount = 0
|
|
114
114
|
} = {}) {
|
|
115
|
-
if (!(0, _utils.hasPointerEvents)(element))
|
|
115
|
+
if (!(0, _utils.hasPointerEvents)(element)) {
|
|
116
|
+
throw new Error('unable to click element as it has or inherits pointer-events set to "none".');
|
|
117
|
+
}
|
|
118
|
+
|
|
116
119
|
if (!skipHover) (0, _hover.hover)(element, init);
|
|
117
120
|
|
|
118
121
|
if ((0, _utils.isElementType)(element, 'label')) {
|
|
@@ -145,7 +148,10 @@ function fireClick(element, mouseEventOptions) {
|
|
|
145
148
|
}
|
|
146
149
|
|
|
147
150
|
function dblClick(element, init) {
|
|
148
|
-
if (!(0, _utils.hasPointerEvents)(element))
|
|
151
|
+
if (!(0, _utils.hasPointerEvents)(element)) {
|
|
152
|
+
throw new Error('unable to double-click element as it has or inherits pointer-events set to "none".');
|
|
153
|
+
}
|
|
154
|
+
|
|
149
155
|
(0, _hover.hover)(element, init);
|
|
150
156
|
click(element, init, {
|
|
151
157
|
skipHover: true,
|
package/dist/hover.js
CHANGED
|
@@ -23,7 +23,10 @@ function getParentElements(element) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
function hover(element, init) {
|
|
26
|
-
if (!(0, _utils.hasPointerEvents)(element))
|
|
26
|
+
if (!(0, _utils.hasPointerEvents)(element)) {
|
|
27
|
+
throw new Error('unable to hover element as it has or inherits pointer-events set to "none".');
|
|
28
|
+
}
|
|
29
|
+
|
|
27
30
|
if ((0, _utils.isLabelWithInternallyDisabledControl)(element)) return;
|
|
28
31
|
const parentElements = getParentElements(element).reverse();
|
|
29
32
|
|
|
@@ -49,7 +52,10 @@ function hover(element, init) {
|
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
function unhover(element, init) {
|
|
52
|
-
if (!(0, _utils.hasPointerEvents)(element))
|
|
55
|
+
if (!(0, _utils.hasPointerEvents)(element)) {
|
|
56
|
+
throw new Error('unable to unhover element as it has or inherits pointer-events set to "none".');
|
|
57
|
+
}
|
|
58
|
+
|
|
53
59
|
if ((0, _utils.isLabelWithInternallyDisabledControl)(element)) return;
|
|
54
60
|
const parentElements = getParentElements(element);
|
|
55
61
|
|
|
@@ -20,18 +20,18 @@ function getNextKeyDef(text, options) {
|
|
|
20
20
|
const startBracket = ['{', '['].includes(text[0]) ? text[0] : '';
|
|
21
21
|
const startModifier = startBracket && text[1] === '/' ? '/' : '';
|
|
22
22
|
const descriptorStart = startBracket.length + startModifier.length;
|
|
23
|
-
const descriptor = startBracket ? text[descriptorStart] === startBracket ? startBracket : (_text$slice$match = text.slice(descriptorStart).match(/^\w+/)) == null ? void 0 : _text$slice$match[0] : text[descriptorStart];
|
|
23
|
+
const descriptor = startBracket ? text[descriptorStart] === startBracket ? startBracket : (_text$slice$match = text.slice(descriptorStart).match(/^\w+/)) == null ? void 0 : _text$slice$match[0] : text[descriptorStart];
|
|
24
24
|
|
|
25
25
|
if (!descriptor) {
|
|
26
|
-
throw new Error(
|
|
26
|
+
throw new Error(getErrorMessage('key descriptor', text[descriptorStart], text));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const descriptorEnd = descriptorStart + descriptor.length;
|
|
30
30
|
const endModifier = startBracket && descriptor !== startBracket && ['/', '>'].includes(text[descriptorEnd]) ? text[descriptorEnd] : '';
|
|
31
|
-
const endBracket = !startBracket || descriptor === startBracket ? '' : startBracket === '{' ? '}' : ']';
|
|
31
|
+
const endBracket = !startBracket || descriptor === startBracket ? '' : startBracket === '{' ? '}' : ']';
|
|
32
32
|
|
|
33
33
|
if (endBracket && text[descriptorEnd + endModifier.length] !== endBracket) {
|
|
34
|
-
throw new Error(
|
|
34
|
+
throw new Error(getErrorMessage('closing bracket', text[descriptorEnd + endModifier.length], text));
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const modifiers = {
|
|
@@ -104,4 +104,8 @@ function mapLegacyKey(descriptor) {
|
|
|
104
104
|
|
|
105
105
|
function isPrintableCharacter(startBracket, descriptor) {
|
|
106
106
|
return !startBracket || startBracket === descriptor || startBracket === '{' && descriptor.length === 1;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getErrorMessage(expected, found, text) {
|
|
110
|
+
return `Expected ${expected} but found "${found != null ? found : ''}" in "${text}"`;
|
|
107
111
|
}
|
package/dist/tab.js
CHANGED
|
@@ -14,15 +14,13 @@ var _focus = require("./focus");
|
|
|
14
14
|
var _blur = require("./blur");
|
|
15
15
|
|
|
16
16
|
function getNextElement(currentIndex, shift, elements, focusTrap) {
|
|
17
|
-
if (focusTrap ===
|
|
18
|
-
return
|
|
19
|
-
} else if (focusTrap === document && currentIndex === elements.length - 1 && !shift) {
|
|
20
|
-
return document.body;
|
|
21
|
-
} else {
|
|
22
|
-
const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
|
|
23
|
-
const defaultIndex = shift ? elements.length - 1 : 0;
|
|
24
|
-
return elements[nextIndex] || elements[defaultIndex];
|
|
17
|
+
if ((0, _utils.isDocument)(focusTrap) && (currentIndex === 0 && shift || currentIndex === elements.length - 1 && !shift)) {
|
|
18
|
+
return focusTrap.body;
|
|
25
19
|
}
|
|
20
|
+
|
|
21
|
+
const nextIndex = shift ? currentIndex - 1 : currentIndex + 1;
|
|
22
|
+
const defaultIndex = shift ? elements.length - 1 : 0;
|
|
23
|
+
return elements[nextIndex] || elements[defaultIndex];
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
function tab({
|
|
@@ -31,10 +29,11 @@ function tab({
|
|
|
31
29
|
} = {}) {
|
|
32
30
|
var _focusTrap$ownerDocum, _focusTrap;
|
|
33
31
|
|
|
34
|
-
const
|
|
32
|
+
const doc = (_focusTrap$ownerDocum = (_focusTrap = focusTrap) == null ? void 0 : _focusTrap.ownerDocument) != null ? _focusTrap$ownerDocum : document;
|
|
33
|
+
const previousElement = (0, _utils.getActiveElement)(doc);
|
|
35
34
|
|
|
36
35
|
if (!focusTrap) {
|
|
37
|
-
focusTrap =
|
|
36
|
+
focusTrap = doc;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
const focusableElements = focusTrap.querySelectorAll(_utils.FOCUSABLE_SELECTOR);
|
|
@@ -120,7 +119,7 @@ function tab({
|
|
|
120
119
|
const keyUpTarget = !continueToTab && previousElement ? previousElement : nextElement;
|
|
121
120
|
|
|
122
121
|
if (continueToTab) {
|
|
123
|
-
if (nextElement ===
|
|
122
|
+
if (nextElement === doc.body) {
|
|
124
123
|
/* istanbul ignore else */
|
|
125
124
|
if (previousElement) {
|
|
126
125
|
(0, _blur.blur)(previousElement);
|
|
@@ -57,5 +57,8 @@ async function typeImplementation(element, text, {
|
|
|
57
57
|
|
|
58
58
|
if (!skipAutoClose) {
|
|
59
59
|
releaseAllKeys();
|
|
60
|
-
}
|
|
60
|
+
} // eslint-disable-next-line consistent-return -- we need to return the internal Promise so that it is catchable if we don't await
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
return promise;
|
|
61
64
|
}
|
|
@@ -7,7 +7,7 @@ exports.isClickableInput = isClickableInput;
|
|
|
7
7
|
|
|
8
8
|
var _isElementType = require("../misc/isElementType");
|
|
9
9
|
|
|
10
|
-
const CLICKABLE_INPUT_TYPES = ['button', 'color', 'file', 'image', 'reset', 'submit'];
|
|
10
|
+
const CLICKABLE_INPUT_TYPES = ['button', 'color', 'file', 'image', 'reset', 'submit', 'checkbox', 'radio'];
|
|
11
11
|
|
|
12
12
|
function isClickableInput(element) {
|
|
13
13
|
return (0, _isElementType.isElementType)(element, 'button') || (0, _isElementType.isElementType)(element, 'input') && CLICKABLE_INPUT_TYPES.includes(element.type);
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -19,5 +19,6 @@ export * from './misc/isElementType';
|
|
|
19
19
|
export * from './misc/isLabelWithInternallyDisabledControl';
|
|
20
20
|
export * from './misc/isVisible';
|
|
21
21
|
export * from './misc/isDisabled';
|
|
22
|
+
export * from './misc/isDocument';
|
|
22
23
|
export * from './misc/wait';
|
|
23
24
|
export * from './misc/hasPointerEvents';
|
package/dist/utils/index.js
CHANGED
|
@@ -277,6 +277,19 @@ Object.keys(_isDisabled).forEach(function (key) {
|
|
|
277
277
|
});
|
|
278
278
|
});
|
|
279
279
|
|
|
280
|
+
var _isDocument = require("./misc/isDocument");
|
|
281
|
+
|
|
282
|
+
Object.keys(_isDocument).forEach(function (key) {
|
|
283
|
+
if (key === "default" || key === "__esModule") return;
|
|
284
|
+
if (key in exports && exports[key] === _isDocument[key]) return;
|
|
285
|
+
Object.defineProperty(exports, key, {
|
|
286
|
+
enumerable: true,
|
|
287
|
+
get: function () {
|
|
288
|
+
return _isDocument[key];
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
280
293
|
var _wait = require("./misc/wait");
|
|
281
294
|
|
|
282
295
|
Object.keys(_wait).forEach(function (key) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isDocument(el: Document | Element): el is Document;
|