@testing-library/user-event 12.5.0 → 12.6.3
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 +51 -5
- package/dist/index.js +6 -0
- package/dist/select-options.js +57 -36
- package/dist/type.js +64 -39
- package/dist/upload.js +2 -10
- package/dist/utils.js +33 -1
- package/package.json +7 -7
- package/typings/index.d.ts +15 -0
package/README.md
CHANGED
|
@@ -47,6 +47,7 @@ change the state of the checkbox.
|
|
|
47
47
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
48
48
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
49
49
|
|
|
50
|
+
|
|
50
51
|
- [Installation](#installation)
|
|
51
52
|
- [API](#api)
|
|
52
53
|
- [`click(element, eventInit, options)`](#clickelement-eventinit-options)
|
|
@@ -60,6 +61,7 @@ change the state of the checkbox.
|
|
|
60
61
|
- [`hover(element)`](#hoverelement)
|
|
61
62
|
- [`unhover(element)`](#unhoverelement)
|
|
62
63
|
- [`paste(element, text, eventInit, options)`](#pasteelement-text-eventinit-options)
|
|
64
|
+
- [`specialChars`](#specialchars)
|
|
63
65
|
- [Issues](#issues)
|
|
64
66
|
- [🐛 Bugs](#-bugs)
|
|
65
67
|
- [💡 Feature Requests](#-feature-requests)
|
|
@@ -118,7 +120,7 @@ test('click', () => {
|
|
|
118
120
|
)
|
|
119
121
|
|
|
120
122
|
userEvent.click(screen.getByText('Check'))
|
|
121
|
-
expect(screen.getByLabelText('Check')).
|
|
123
|
+
expect(screen.getByLabelText('Check')).toBeChecked()
|
|
122
124
|
})
|
|
123
125
|
```
|
|
124
126
|
|
|
@@ -147,8 +149,8 @@ import userEvent from '@testing-library/user-event'
|
|
|
147
149
|
|
|
148
150
|
test('double click', () => {
|
|
149
151
|
const onChange = jest.fn()
|
|
150
|
-
render(<input type="checkbox"
|
|
151
|
-
const checkbox = screen.
|
|
152
|
+
render(<input type="checkbox" onChange={onChange} />)
|
|
153
|
+
const checkbox = screen.getByRole('checkbox')
|
|
152
154
|
userEvent.dblClick(checkbox)
|
|
153
155
|
expect(onChange).toHaveBeenCalledTimes(2)
|
|
154
156
|
expect(checkbox).not.toBeChecked()
|
|
@@ -519,6 +521,47 @@ test('should paste text in input', () => {
|
|
|
519
521
|
You can use the `eventInit` if what you're pasting should have `clipboardData`
|
|
520
522
|
(like `files`).
|
|
521
523
|
|
|
524
|
+
### `specialChars`
|
|
525
|
+
|
|
526
|
+
A handful set of special characters used in [type](#typeelement-text-options)
|
|
527
|
+
method.
|
|
528
|
+
|
|
529
|
+
| Key | Character |
|
|
530
|
+
| ---------- | -------------- |
|
|
531
|
+
| arrowLeft | `{arrowleft}` |
|
|
532
|
+
| arrowRight | `{arrowright}` |
|
|
533
|
+
| arrowDown | `{arrowdown}` |
|
|
534
|
+
| arrowUp | `{arrowup}` |
|
|
535
|
+
| enter | `{enter}` |
|
|
536
|
+
| escape | `{esc}` |
|
|
537
|
+
| delete | `{del}` |
|
|
538
|
+
| backspace | `{backspace}` |
|
|
539
|
+
| selectAll | `{selectall}` |
|
|
540
|
+
| space | `{space}` |
|
|
541
|
+
| whitespace | `' '` |
|
|
542
|
+
|
|
543
|
+
Usage example:
|
|
544
|
+
|
|
545
|
+
```jsx
|
|
546
|
+
import React from 'react'
|
|
547
|
+
import {render, screen} from '@testing-library/react'
|
|
548
|
+
import userEvent, {specialChars} from '@testing-library/user-event'
|
|
549
|
+
|
|
550
|
+
test('delete characters within the selectedRange', () => {
|
|
551
|
+
render(
|
|
552
|
+
<div>
|
|
553
|
+
<label htmlFor="my-input">Example:</label>
|
|
554
|
+
<input id="my-input" type="text" value="This is a bad example" />
|
|
555
|
+
</div>,
|
|
556
|
+
)
|
|
557
|
+
const input = screen.getByLabelText(/example/i)
|
|
558
|
+
input.setSelectionRange(10, 13)
|
|
559
|
+
userEvent.type(input, `${specialChars.backspace}good`)
|
|
560
|
+
|
|
561
|
+
expect(input).toHaveValue('This is a good example')
|
|
562
|
+
})
|
|
563
|
+
```
|
|
564
|
+
|
|
522
565
|
## Issues
|
|
523
566
|
|
|
524
567
|
_Looking to contribute? Look for the [Good First Issue][good-first-issue]
|
|
@@ -597,7 +640,7 @@ Thanks goes to these people ([emoji key][emojis]):
|
|
|
597
640
|
<td align="center"><a href="https://github.com/nanivijay"><img src="https://avatars0.githubusercontent.com/u/5945591?v=4" width="100px;" alt=""/><br /><sub><b>Vijay Kumar Otti</b></sub></a><br /><a href="https://github.com/testing-library/user-event/issues?q=author%3Ananivijay" title="Bug reports">🐛</a></td>
|
|
598
641
|
<td align="center"><a href="http://tompicton.com"><img src="https://avatars2.githubusercontent.com/u/12588098?v=4" width="100px;" alt=""/><br /><sub><b>Tom Picton</b></sub></a><br /><a href="https://github.com/testing-library/user-event/issues?q=author%3Atpict" title="Bug reports">🐛</a> <a href="https://github.com/testing-library/user-event/commits?author=tpict" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=tpict" title="Tests">⚠️</a></td>
|
|
599
642
|
<td align="center"><a href="https://hung.dev"><img src="https://avatars3.githubusercontent.com/u/8603085?v=4" width="100px;" alt=""/><br /><sub><b>Hung Viet Nguyen</b></sub></a><br /><a href="https://github.com/testing-library/user-event/issues?q=author%3Anvh95" title="Bug reports">🐛</a></td>
|
|
600
|
-
<td align="center"><a href="https://nickmccurdy.com/"><img src="https://avatars0.githubusercontent.com/u/927220?v=4" width="100px;" alt=""/><br /><sub><b>Nick McCurdy</b></sub></a><br /><a href="#projectManagement-nickmccurdy" title="Project Management">📆</a> <a href="#question-nickmccurdy" title="Answering Questions">💬</a> <a href="https://github.com/testing-library/user-event/commits?author=nickmccurdy" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=nickmccurdy" title="Tests">⚠️</a></td>
|
|
643
|
+
<td align="center"><a href="https://nickmccurdy.com/"><img src="https://avatars0.githubusercontent.com/u/927220?v=4" width="100px;" alt=""/><br /><sub><b>Nick McCurdy</b></sub></a><br /><a href="#projectManagement-nickmccurdy" title="Project Management">📆</a> <a href="#question-nickmccurdy" title="Answering Questions">💬</a> <a href="https://github.com/testing-library/user-event/commits?author=nickmccurdy" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=nickmccurdy" title="Tests">⚠️</a> <a href="https://github.com/testing-library/user-event/commits?author=nickmccurdy" title="Documentation">📖</a></td>
|
|
601
644
|
</tr>
|
|
602
645
|
<tr>
|
|
603
646
|
<td align="center"><a href="http://timdeschryver.dev"><img src="https://avatars1.githubusercontent.com/u/28659384?v=4" width="100px;" alt=""/><br /><sub><b>Tim Deschryver</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=timdeschryver" title="Tests">⚠️</a></td>
|
|
@@ -635,11 +678,14 @@ Thanks goes to these people ([emoji key][emojis]):
|
|
|
635
678
|
<td align="center"><a href="https://github.com/Sonic12040"><img src="https://avatars3.githubusercontent.com/u/21055893?v=4" width="100px;" alt=""/><br /><sub><b>Sonic12040</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=Sonic12040" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=Sonic12040" title="Tests">⚠️</a> <a href="https://github.com/testing-library/user-event/commits?author=Sonic12040" title="Documentation">📖</a></td>
|
|
636
679
|
<td align="center"><a href="https://github.com/gndelia"><img src="https://avatars1.githubusercontent.com/u/352474?v=4" width="100px;" alt=""/><br /><sub><b>Gonzalo D'Elia</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=gndelia" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=gndelia" title="Tests">⚠️</a> <a href="https://github.com/testing-library/user-event/commits?author=gndelia" title="Documentation">📖</a></td>
|
|
637
680
|
</tr>
|
|
681
|
+
<tr>
|
|
682
|
+
<td align="center"><a href="https://github.com/vasilii-kovalev"><img src="https://avatars0.githubusercontent.com/u/10310491?v=4" width="100px;" alt=""/><br /><sub><b>Vasilii Kovalev</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=vasilii-kovalev" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=vasilii-kovalev" title="Documentation">📖</a></td>
|
|
683
|
+
<td align="center"><a href="https://www.daleseo.com"><img src="https://avatars1.githubusercontent.com/u/5466341?v=4" width="100px;" alt=""/><br /><sub><b>Dale Seo</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=daleseo" title="Documentation">📖</a></td>
|
|
684
|
+
</tr>
|
|
638
685
|
</table>
|
|
639
686
|
|
|
640
687
|
<!-- markdownlint-enable -->
|
|
641
688
|
<!-- prettier-ignore-end -->
|
|
642
|
-
|
|
643
689
|
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
644
690
|
|
|
645
691
|
This project follows the [all-contributors][all-contributors] specification.
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "specialChars", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _type.specialCharMap;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
exports.default = void 0;
|
|
7
13
|
|
|
8
14
|
var _click = require("./click");
|
package/dist/select-options.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.deselectOptions = exports.selectOptions = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _dom = require("@testing-library/dom");
|
|
9
9
|
|
|
10
|
+
var _utils = require("./utils");
|
|
11
|
+
|
|
10
12
|
var _click = require("./click");
|
|
11
13
|
|
|
12
14
|
var _focus = require("./focus");
|
|
@@ -35,59 +37,78 @@ function selectOptionsBase(newValue, select, values, init) {
|
|
|
35
37
|
}).filter(option => !option.disabled);
|
|
36
38
|
if (select.disabled || !selectedOptions.length) return;
|
|
37
39
|
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
if ((0, _utils.isInstanceOfElement)(select, 'HTMLSelectElement')) {
|
|
41
|
+
if (select.multiple) {
|
|
42
|
+
for (const option of selectedOptions) {
|
|
43
|
+
// events fired for multiple select are weird. Can't use hover...
|
|
44
|
+
_dom.fireEvent.pointerOver(option, init);
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
_dom.fireEvent.pointerEnter(select, init);
|
|
44
47
|
|
|
45
|
-
|
|
48
|
+
_dom.fireEvent.mouseOver(option);
|
|
46
49
|
|
|
47
|
-
|
|
50
|
+
_dom.fireEvent.mouseEnter(select);
|
|
51
|
+
|
|
52
|
+
_dom.fireEvent.pointerMove(option, init);
|
|
53
|
+
|
|
54
|
+
_dom.fireEvent.mouseMove(option, init);
|
|
55
|
+
|
|
56
|
+
_dom.fireEvent.pointerDown(option, init);
|
|
48
57
|
|
|
49
|
-
|
|
58
|
+
_dom.fireEvent.mouseDown(option, init);
|
|
50
59
|
|
|
51
|
-
|
|
60
|
+
(0, _focus.focus)(select, init);
|
|
61
|
+
|
|
62
|
+
_dom.fireEvent.pointerUp(option, init);
|
|
63
|
+
|
|
64
|
+
_dom.fireEvent.mouseUp(option, init);
|
|
65
|
+
|
|
66
|
+
selectOption(option);
|
|
67
|
+
|
|
68
|
+
_dom.fireEvent.click(option, init);
|
|
69
|
+
}
|
|
70
|
+
} else if (selectedOptions.length === 1) {
|
|
71
|
+
// the click to open the select options
|
|
72
|
+
(0, _click.click)(select, init);
|
|
73
|
+
selectOption(selectedOptions[0]); // the browser triggers another click event on the select for the click on the option
|
|
74
|
+
// this second click has no 'down' phase
|
|
52
75
|
|
|
53
|
-
_dom.fireEvent.
|
|
76
|
+
_dom.fireEvent.pointerOver(select, init);
|
|
54
77
|
|
|
55
|
-
_dom.fireEvent.
|
|
78
|
+
_dom.fireEvent.pointerEnter(select, init);
|
|
56
79
|
|
|
57
|
-
|
|
80
|
+
_dom.fireEvent.mouseOver(select);
|
|
58
81
|
|
|
59
|
-
_dom.fireEvent.
|
|
82
|
+
_dom.fireEvent.mouseEnter(select);
|
|
60
83
|
|
|
61
|
-
_dom.fireEvent.
|
|
84
|
+
_dom.fireEvent.pointerUp(select, init);
|
|
62
85
|
|
|
63
|
-
|
|
86
|
+
_dom.fireEvent.mouseUp(select, init);
|
|
64
87
|
|
|
65
|
-
_dom.fireEvent.click(
|
|
88
|
+
_dom.fireEvent.click(select, init);
|
|
89
|
+
} else {
|
|
90
|
+
throw (0, _dom.getConfig)().getElementError(`Cannot select multiple options on a non-multiple select`, select);
|
|
66
91
|
}
|
|
67
|
-
} else if (
|
|
68
|
-
|
|
69
|
-
|
|
92
|
+
} else if (select.getAttribute('role') === 'listbox') {
|
|
93
|
+
selectedOptions.forEach(option => {
|
|
94
|
+
(0, _hover.hover)(option, init);
|
|
95
|
+
(0, _click.click)(option, init);
|
|
96
|
+
(0, _hover.unhover)(option, init);
|
|
97
|
+
});
|
|
70
98
|
} else {
|
|
71
|
-
throw (0, _dom.getConfig)().getElementError(`Cannot select
|
|
99
|
+
throw (0, _dom.getConfig)().getElementError(`Cannot select options on elements that are neither select nor listbox elements`, select);
|
|
72
100
|
}
|
|
73
101
|
|
|
74
102
|
function selectOption(option) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
cancelable: false,
|
|
85
|
-
composed: true,
|
|
86
|
-
...init
|
|
87
|
-
}));
|
|
88
|
-
|
|
89
|
-
_dom.fireEvent.change(select, init);
|
|
90
|
-
}
|
|
103
|
+
option.selected = newValue;
|
|
104
|
+
(0, _dom.fireEvent)(select, (0, _dom.createEvent)('input', select, {
|
|
105
|
+
bubbles: true,
|
|
106
|
+
cancelable: false,
|
|
107
|
+
composed: true,
|
|
108
|
+
...init
|
|
109
|
+
}));
|
|
110
|
+
|
|
111
|
+
_dom.fireEvent.change(select, init);
|
|
91
112
|
}
|
|
92
113
|
}
|
|
93
114
|
|
package/dist/type.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.type = type;
|
|
7
|
+
exports.specialCharMap = void 0;
|
|
7
8
|
|
|
8
9
|
var _dom = require("@testing-library/dom");
|
|
9
10
|
|
|
@@ -39,7 +40,7 @@ const modifierCallbackMap = { ...createModifierCallbackEntries({
|
|
|
39
40
|
modifierProperty: 'metaKey'
|
|
40
41
|
}),
|
|
41
42
|
// capslock is inline because of the need to fire both keydown and keyup on use, while preserving the modifier state.
|
|
42
|
-
'{capslock}': function ({
|
|
43
|
+
'{capslock}': function capslockOn({
|
|
43
44
|
currentElement,
|
|
44
45
|
eventOverrides
|
|
45
46
|
}) {
|
|
@@ -67,7 +68,7 @@ const modifierCallbackMap = { ...createModifierCallbackEntries({
|
|
|
67
68
|
eventOverrides: newEventOverrides
|
|
68
69
|
};
|
|
69
70
|
},
|
|
70
|
-
'{/capslock}': function ({
|
|
71
|
+
'{/capslock}': function capslockOff({
|
|
71
72
|
currentElement,
|
|
72
73
|
eventOverrides
|
|
73
74
|
}) {
|
|
@@ -96,18 +97,32 @@ const modifierCallbackMap = { ...createModifierCallbackEntries({
|
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
99
|
};
|
|
100
|
+
const specialCharMap = {
|
|
101
|
+
arrowLeft: '{arrowleft}',
|
|
102
|
+
arrowRight: '{arrowright}',
|
|
103
|
+
arrowDown: '{arrowdown}',
|
|
104
|
+
arrowUp: '{arrowup}',
|
|
105
|
+
enter: '{enter}',
|
|
106
|
+
escape: '{esc}',
|
|
107
|
+
delete: '{del}',
|
|
108
|
+
backspace: '{backspace}',
|
|
109
|
+
selectAll: '{selectall}',
|
|
110
|
+
space: '{space}',
|
|
111
|
+
whitespace: ' '
|
|
112
|
+
};
|
|
113
|
+
exports.specialCharMap = specialCharMap;
|
|
99
114
|
const specialCharCallbackMap = {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
115
|
+
[specialCharMap.arrowLeft]: (0, _navigationKey.navigationKey)('ArrowLeft'),
|
|
116
|
+
[specialCharMap.arrowRight]: (0, _navigationKey.navigationKey)('ArrowRight'),
|
|
117
|
+
[specialCharMap.arrowDown]: handleArrowDown,
|
|
118
|
+
[specialCharMap.arrowUp]: handleArrowUp,
|
|
119
|
+
[specialCharMap.enter]: handleEnter,
|
|
120
|
+
[specialCharMap.escape]: handleEsc,
|
|
121
|
+
[specialCharMap.delete]: handleDel,
|
|
122
|
+
[specialCharMap.backspace]: handleBackspace,
|
|
123
|
+
[specialCharMap.selectAll]: handleSelectall,
|
|
124
|
+
[specialCharMap.space]: handleSpace,
|
|
125
|
+
[specialCharMap.whitespace]: handleSpace
|
|
111
126
|
};
|
|
112
127
|
|
|
113
128
|
function wait(time) {
|
|
@@ -180,7 +195,10 @@ async function typeImpl(element, text, {
|
|
|
180
195
|
(0, _utils.setSelectionRangeIfNecessary)(currentElement(), initialSelectionStart != null ? initialSelectionStart : value.length, initialSelectionEnd != null ? initialSelectionEnd : value.length);
|
|
181
196
|
}
|
|
182
197
|
|
|
183
|
-
const eventCallbacks =
|
|
198
|
+
const eventCallbacks = queueCallbacks();
|
|
199
|
+
await runCallbacks(eventCallbacks);
|
|
200
|
+
|
|
201
|
+
function queueCallbacks() {
|
|
184
202
|
const callbacks = [];
|
|
185
203
|
let remainingString = text;
|
|
186
204
|
|
|
@@ -194,9 +212,9 @@ async function typeImpl(element, text, {
|
|
|
194
212
|
}
|
|
195
213
|
|
|
196
214
|
return callbacks;
|
|
197
|
-
}
|
|
215
|
+
}
|
|
198
216
|
|
|
199
|
-
|
|
217
|
+
async function runCallbacks(callbacks) {
|
|
200
218
|
const eventOverrides = {};
|
|
201
219
|
let prevWasMinus, prevWasPeriod, prevValue, typedValue;
|
|
202
220
|
|
|
@@ -219,7 +237,7 @@ async function typeImpl(element, text, {
|
|
|
219
237
|
typedValue = returnValue == null ? void 0 : returnValue.typedValue;
|
|
220
238
|
}
|
|
221
239
|
}
|
|
222
|
-
}
|
|
240
|
+
}
|
|
223
241
|
}
|
|
224
242
|
|
|
225
243
|
function getNextCallback(remainingString, skipAutoClose) {
|
|
@@ -275,8 +293,11 @@ function getSpecialCharCallback(remainingString) {
|
|
|
275
293
|
|
|
276
294
|
function getTypeCallback(remainingString) {
|
|
277
295
|
const character = remainingString[0];
|
|
296
|
+
|
|
297
|
+
const callback = context => typeCharacter(character, context);
|
|
298
|
+
|
|
278
299
|
return {
|
|
279
|
-
callback
|
|
300
|
+
callback,
|
|
280
301
|
remainingString: remainingString.slice(1)
|
|
281
302
|
};
|
|
282
303
|
}
|
|
@@ -542,6 +563,7 @@ function createModifierCallbackEntries({
|
|
|
542
563
|
keyCode,
|
|
543
564
|
modifierProperty
|
|
544
565
|
}) {
|
|
566
|
+
const openName = `{${name}}`;
|
|
545
567
|
const closeName = `{/${name}}`;
|
|
546
568
|
|
|
547
569
|
function open({
|
|
@@ -566,28 +588,31 @@ function createModifierCallbackEntries({
|
|
|
566
588
|
}
|
|
567
589
|
|
|
568
590
|
open.closeName = closeName;
|
|
569
|
-
return {
|
|
570
|
-
[`{${name}}`]: open,
|
|
571
|
-
[closeName]: function ({
|
|
572
|
-
currentElement,
|
|
573
|
-
eventOverrides
|
|
574
|
-
}) {
|
|
575
|
-
const newEventOverrides = {
|
|
576
|
-
[modifierProperty]: false
|
|
577
|
-
};
|
|
578
|
-
|
|
579
|
-
_dom.fireEvent.keyUp(currentElement(), {
|
|
580
|
-
key,
|
|
581
|
-
keyCode,
|
|
582
|
-
which: keyCode,
|
|
583
|
-
...eventOverrides,
|
|
584
|
-
...newEventOverrides
|
|
585
|
-
});
|
|
586
591
|
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
592
|
+
function close({
|
|
593
|
+
currentElement,
|
|
594
|
+
eventOverrides
|
|
595
|
+
}) {
|
|
596
|
+
const newEventOverrides = {
|
|
597
|
+
[modifierProperty]: false
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
_dom.fireEvent.keyUp(currentElement(), {
|
|
601
|
+
key,
|
|
602
|
+
keyCode,
|
|
603
|
+
which: keyCode,
|
|
604
|
+
...eventOverrides,
|
|
605
|
+
...newEventOverrides
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
return {
|
|
609
|
+
eventOverrides: newEventOverrides
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return {
|
|
614
|
+
[openName]: open,
|
|
615
|
+
[closeName]: close
|
|
591
616
|
};
|
|
592
617
|
}
|
|
593
618
|
|
package/dist/upload.js
CHANGED
|
@@ -15,17 +15,9 @@ var _focus = require("./focus");
|
|
|
15
15
|
|
|
16
16
|
function upload(element, fileOrFiles, init) {
|
|
17
17
|
if (element.disabled) return;
|
|
18
|
-
let files;
|
|
19
|
-
let input = element;
|
|
20
18
|
(0, _click.click)(element, init);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
files = element.control.multiple ? fileOrFiles : [fileOrFiles];
|
|
24
|
-
input = element.control;
|
|
25
|
-
} else {
|
|
26
|
-
files = element.multiple ? fileOrFiles : [fileOrFiles];
|
|
27
|
-
} // blur fires when the file selector pops up
|
|
28
|
-
|
|
19
|
+
const input = element.tagName === 'LABEL' ? element.control : element;
|
|
20
|
+
const files = (Array.isArray(fileOrFiles) ? fileOrFiles : [fileOrFiles]).slice(0, input.multiple ? undefined : 1); // blur fires when the file selector pops up
|
|
29
21
|
|
|
30
22
|
(0, _blur.blur)(element, init); // focus fires when they make their selection
|
|
31
23
|
|
package/dist/utils.js
CHANGED
|
@@ -17,10 +17,42 @@ exports.buildTimeValue = buildTimeValue;
|
|
|
17
17
|
exports.getValue = getValue;
|
|
18
18
|
exports.getSelectionRange = getSelectionRange;
|
|
19
19
|
exports.isContentEditable = isContentEditable;
|
|
20
|
+
exports.isInstanceOfElement = isInstanceOfElement;
|
|
20
21
|
exports.FOCUSABLE_SELECTOR = void 0;
|
|
21
22
|
|
|
22
23
|
var _dom = require("@testing-library/dom");
|
|
23
24
|
|
|
25
|
+
var _helpers = require("@testing-library/dom/dist/helpers");
|
|
26
|
+
|
|
27
|
+
// isInstanceOfElement can be removed once the peerDependency for @testing-library/dom is bumped to a version that includes https://github.com/testing-library/dom-testing-library/pull/885
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Check if an element is of a given type.
|
|
31
|
+
*
|
|
32
|
+
* @param Element The element to test
|
|
33
|
+
* @param string Constructor name. E.g. 'HTMLSelectElement'
|
|
34
|
+
*/
|
|
35
|
+
function isInstanceOfElement(element, elementType) {
|
|
36
|
+
try {
|
|
37
|
+
const window = (0, _helpers.getWindowFromNode)(element); // Window usually has the element constructors as properties but is not required to do so per specs
|
|
38
|
+
|
|
39
|
+
if (typeof window[elementType] === 'function') {
|
|
40
|
+
return element instanceof window[elementType];
|
|
41
|
+
}
|
|
42
|
+
} catch (e) {// The document might not be associated with a window
|
|
43
|
+
} // Fall back to the constructor name as workaround for test environments that
|
|
44
|
+
// a) not associate the document with a window
|
|
45
|
+
// b) not provide the constructor as property of window
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if (/^HTML(\w+)Element$/.test(element.constructor.name)) {
|
|
49
|
+
return element.constructor.name === elementType;
|
|
50
|
+
} // The user passed some node that is not created in a browser-like environment
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
throw new Error(`Unable to verify if element is instance of ${elementType}. Please file an issue describing your test environment: https://github.com/testing-library/dom-testing-library/issues/new`);
|
|
54
|
+
}
|
|
55
|
+
|
|
24
56
|
function isMousePressEvent(event) {
|
|
25
57
|
return event === 'mousedown' || event === 'mouseup' || event === 'click' || event === 'dblclick';
|
|
26
58
|
}
|
|
@@ -243,7 +275,7 @@ function isFocusable(element) {
|
|
|
243
275
|
const CLICKABLE_INPUT_TYPES = ['button', 'color', 'file', 'image', 'reset', 'submit'];
|
|
244
276
|
|
|
245
277
|
function isClickable(element) {
|
|
246
|
-
return element.tagName === 'BUTTON' || element
|
|
278
|
+
return element.tagName === 'BUTTON' || isInstanceOfElement(element, 'HTMLInputElement') && CLICKABLE_INPUT_TYPES.includes(element.type);
|
|
247
279
|
}
|
|
248
280
|
|
|
249
281
|
function eventWrapper(cb) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testing-library/user-event",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.6.3",
|
|
4
4
|
"description": "Fire events the same way the user does",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "typings/index.d.ts",
|
|
@@ -36,19 +36,19 @@
|
|
|
36
36
|
"test:debug": "kcd-scripts --inspect-brk test --runInBand",
|
|
37
37
|
"test:update": "npm test -- --updateSnapshot --coverage",
|
|
38
38
|
"validate": "kcd-scripts validate",
|
|
39
|
-
"typecheck": "
|
|
39
|
+
"typecheck": "kcd-scripts typecheck --build typings"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@babel/runtime": "^7.
|
|
42
|
+
"@babel/runtime": "^7.12.5"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@testing-library/dom": "^7.
|
|
46
|
-
"@testing-library/jest-dom": "^5.11.
|
|
45
|
+
"@testing-library/dom": "^7.28.1",
|
|
46
|
+
"@testing-library/jest-dom": "^5.11.6",
|
|
47
47
|
"@types/estree": "0.0.45",
|
|
48
48
|
"is-ci": "^2.0.0",
|
|
49
49
|
"jest-serializer-ansi": "^1.0.3",
|
|
50
|
-
"kcd-scripts": "^
|
|
51
|
-
"typescript": "^4.
|
|
50
|
+
"kcd-scripts": "^7.5.1",
|
|
51
|
+
"typescript": "^4.1.2"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@testing-library/dom": ">=7.21.4"
|
package/typings/index.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ declare const userEvent: {
|
|
|
57
57
|
element: TargetElement,
|
|
58
58
|
text: string,
|
|
59
59
|
userOpts?: T,
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
|
60
61
|
) => T extends {delay: number} ? Promise<void> : void
|
|
61
62
|
tab: (userOpts?: ITabUserOptions) => void
|
|
62
63
|
paste: (
|
|
@@ -73,3 +74,17 @@ declare const userEvent: {
|
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
export default userEvent
|
|
77
|
+
|
|
78
|
+
export enum specialChars {
|
|
79
|
+
arrowLeft = '{arrowleft}',
|
|
80
|
+
arrowRight = '{arrowright}',
|
|
81
|
+
arrowDown = '{arrowdown}',
|
|
82
|
+
arrowUp = '{arrowup}',
|
|
83
|
+
enter = '{enter}',
|
|
84
|
+
escape = '{esc}',
|
|
85
|
+
delete = '{del}',
|
|
86
|
+
backspace = '{backspace}',
|
|
87
|
+
selectAll = '{selectall}',
|
|
88
|
+
space = '{space}',
|
|
89
|
+
whitespace = ' ',
|
|
90
|
+
}
|