@testing-library/user-event 12.5.0 → 12.6.0
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 +46 -1
- package/dist/index.js +6 -0
- package/dist/type.js +26 -11
- 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)
|
|
@@ -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]
|
|
@@ -635,11 +678,13 @@ 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
|
+
</tr>
|
|
638
684
|
</table>
|
|
639
685
|
|
|
640
686
|
<!-- markdownlint-enable -->
|
|
641
687
|
<!-- prettier-ignore-end -->
|
|
642
|
-
|
|
643
688
|
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
644
689
|
|
|
645
690
|
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/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
|
|
|
@@ -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) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testing-library/user-event",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.6.0",
|
|
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
|
+
}
|