@testing-library/user-event 12.1.9 → 12.2.2

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 CHANGED
@@ -21,10 +21,7 @@
21
21
  [![version][version-badge]][package]
22
22
  [![downloads][downloads-badge]][npmtrends]
23
23
  [![MIT License][license-badge]][license]
24
-
25
- <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
26
- [![All Contributors](https://img.shields.io/badge/all_contributors-64-orange.svg?style=flat-square)](#contributors-)
27
- <!-- ALL-CONTRIBUTORS-BADGE:END -->
24
+ [![All Contributors][all-contributors-badge]](#contributors)
28
25
  [![PRs Welcome][prs-badge]][prs]
29
26
  [![Code of Conduct][coc-badge]][coc]
30
27
  <!-- prettier-ignore-end -->
@@ -175,9 +172,9 @@ are typed. By default it's 0. You can use this option if your component has a
175
172
  different behavior for fast or slow users. If you do this, you need to make sure
176
173
  to `await`!
177
174
 
178
- > To be clear, `userEvent.type` *always* returns a promise, but you *only* need
179
- > to `await` the promise it returns if you're using the `delay` option. Otherwise
180
- > everything runs synchronously and you can ignore the promise.
175
+ > To be clear, `userEvent.type` _always_ returns a promise, but you _only_ need
176
+ > to `await` the promise it returns if you're using the `delay` option.
177
+ > Otherwise everything runs synchronously and you can ignore the promise.
181
178
 
182
179
  `type` will click the element before typing. To disable this, set the
183
180
  `skipClick` option to `true`.
@@ -186,18 +183,20 @@ to `await`!
186
183
 
187
184
  The following special character strings are supported:
188
185
 
189
- | Text string | Key | Modifier | Notes |
190
- | ------------- | --------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
191
- | `{enter}` | Enter | N/A | Will insert a newline character (`<textarea />` only). |
192
- | `{space}` | `' '` | N/A | |
193
- | `{esc}` | Escape | N/A | |
194
- | `{backspace}` | Backspace | N/A | Will delete the previous character (or the characters within the `selectedRange`, see example below). |
195
- | `{del}` | Delete | N/A | Will delete the next character (or the characters within the `selectedRange`, see example below) |
196
- | `{selectall}` | N/A | N/A | Selects all the text of the element. Note that this will only work for elements that support selection ranges (so, not `email`, `password`, `number`, among others) |
197
- | `{shift}` | Shift | `shiftKey` | Does **not** capitalize following characters. |
198
- | `{ctrl}` | Control | `ctrlKey` | |
199
- | `{alt}` | Alt | `altKey` | |
200
- | `{meta}` | OS | `metaKey` | |
186
+ | Text string | Key | Modifier | Notes |
187
+ | -------------- | ---------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
188
+ | `{enter}` | Enter | N/A | Will insert a newline character (`<textarea />` only). |
189
+ | `{space}` | `' '` | N/A | |
190
+ | `{esc}` | Escape | N/A | |
191
+ | `{backspace}` | Backspace | N/A | Will delete the previous character (or the characters within the `selectedRange`, see example below). |
192
+ | `{del}` | Delete | N/A | Will delete the next character (or the characters within the `selectedRange`, see example below) |
193
+ | `{selectall}` | N/A | N/A | Selects all the text of the element. Note that this will only work for elements that support selection ranges (so, not `email`, `password`, `number`, among others) |
194
+ | `{arrowleft}` | ArrowLeft | N/A | |
195
+ | `{arrowright}` | ArrowRight | N/A | |
196
+ | `{shift}` | Shift | `shiftKey` | Does **not** capitalize following characters. |
197
+ | `{ctrl}` | Control | `ctrlKey` | |
198
+ | `{alt}` | Alt | `altKey` | |
199
+ | `{meta}` | OS | `metaKey` | |
201
200
 
202
201
  > **A note about modifiers:** Modifier keys (`{shift}`, `{ctrl}`, `{alt}`,
203
202
  > `{meta}`) will activate their corresponding event modifiers for the duration
@@ -594,7 +593,10 @@ Thanks goes to these people ([emoji key][emojis]):
594
593
  <td align="center"><a href="https://github.com/lazytype"><img src="https://avatars1.githubusercontent.com/u/840985?v=4" width="100px;" alt=""/><br /><sub><b>lazytype</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=lazytype" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=lazytype" title="Tests">⚠️</a></td>
595
594
  </tr>
596
595
  <tr>
597
- <td align="center"><a href="https://www.linkedin.com/in/luis-takahashi/"><img src="https://avatars0.githubusercontent.com/u/19766035?v=4" width="100px;" alt=""/><br /><sub><b>Luís Takahashi</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=luistak" title="Code">💻</a></td>
596
+ <td align="center"><a href="https://www.linkedin.com/in/luis-takahashi/"><img src="https://avatars0.githubusercontent.com/u/19766035?v=4" width="100px;" alt=""/><br /><sub><b>Luís Takahashi</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=luistak" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=luistak" title="Tests">⚠️</a></td>
597
+ <td align="center"><a href="https://github.com/jesujcastillom"><img src="https://avatars3.githubusercontent.com/u/7827281?v=4" width="100px;" alt=""/><br /><sub><b>Jesu Castillo</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=jesujcastillom" title="Code">💻</a> <a href="https://github.com/testing-library/user-event/commits?author=jesujcastillom" title="Tests">⚠️</a></td>
598
+ <td align="center"><a href="https://sarahdayan.dev"><img src="https://avatars1.githubusercontent.com/u/5370675?v=4" width="100px;" alt=""/><br /><sub><b>Sarah Dayan</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=sarahdayan" title="Documentation">📖</a></td>
599
+ <td align="center"><a href="http://saul-mirone.github.io/"><img src="https://avatars0.githubusercontent.com/u/10047788?v=4" width="100px;" alt=""/><br /><sub><b>Mirone</b></sub></a><br /><a href="https://github.com/testing-library/user-event/issues?q=author%3ASaul-Mirone" title="Bug reports">🐛</a></td>
598
600
  </tr>
599
601
  </table>
600
602
 
@@ -612,8 +614,8 @@ MIT
612
614
  <!-- prettier-ignore-start -->
613
615
  [npm]: https://www.npmjs.com
614
616
  [node]: https://nodejs.org
615
- [build-badge]: https://img.shields.io/travis/testing-library/user-event.svg?style=flat-square
616
- [build]: https://travis-ci.org/testing-library/user-event
617
+ [build-badge]: https://img.shields.io/github/workflow/status/testing-library/user-event/validate/main?logo=github&style=flat-square
618
+ [build]: https://github.com/testing-library/user-event/actions?query=workflow%3Avalidate
617
619
  [coverage-badge]: https://img.shields.io/codecov/c/github/testing-library/user-event.svg?style=flat-square
618
620
  [coverage]: https://codecov.io/github/testing-library/user-event
619
621
  [version-badge]: https://img.shields.io/npm/v/@testing-library/user-event.svg?style=flat-square
@@ -628,6 +630,7 @@ MIT
628
630
  [coc]: https://github.com/testing-library/user-event/blob/master/other/CODE_OF_CONDUCT.md
629
631
  [emojis]: https://github.com/all-contributors/all-contributors#emoji-key
630
632
  [all-contributors]: https://github.com/all-contributors/all-contributors
633
+ [all-contributors-badge]: https://img.shields.io/github/all-contributors/testing-library/user-event?color=orange&style=flat-square
631
634
  [bugs]: https://github.com/testing-library/user-event/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Acreated-desc+label%3Abug
632
635
  [requests]: https://github.com/testing-library/user-event/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3Aenhancement
633
636
  [good-first-issue]: https://github.com/testing-library/user-event/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3Aenhancement+label%3A%22good+first+issue%22
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.navigationKey = navigationKey;
7
+
8
+ var _dom = require("@testing-library/dom");
9
+
10
+ var _utils = require("../utils");
11
+
12
+ const keys = {
13
+ ArrowLeft: {
14
+ keyCode: 37
15
+ },
16
+ ArrowRight: {
17
+ keyCode: 39
18
+ }
19
+ };
20
+
21
+ function getSelectionRange(currentElement, key) {
22
+ const {
23
+ selectionStart,
24
+ selectionEnd
25
+ } = currentElement();
26
+ const cursorChange = Number(key in keys) * (key === 'ArrowLeft' ? -1 : 1);
27
+ return {
28
+ selectionStart: selectionStart + cursorChange,
29
+ selectionEnd: selectionEnd + cursorChange
30
+ };
31
+ }
32
+
33
+ function navigationKey(key) {
34
+ const event = {
35
+ key,
36
+ keyCode: keys[key].keyCode,
37
+ which: keys[key].keyCode
38
+ };
39
+ return ({
40
+ currentElement,
41
+ eventOverrides
42
+ }) => {
43
+ _dom.fireEvent.keyDown(currentElement(), { ...event,
44
+ ...eventOverrides
45
+ });
46
+
47
+ const range = getSelectionRange(currentElement, key);
48
+ (0, _utils.setSelectionRangeIfNecessary)(currentElement(), range.selectionStart, range.selectionEnd);
49
+
50
+ _dom.fireEvent.keyUp(currentElement(), { ...event,
51
+ ...eventOverrides
52
+ });
53
+ };
54
+ }
@@ -11,6 +11,8 @@ var _click = require("./click");
11
11
 
12
12
  var _focus = require("./focus");
13
13
 
14
+ var _hover = require("./hover");
15
+
14
16
  function selectOptionsBase(newValue, select, values, init) {
15
17
  if (!newValue && !select.multiple) {
16
18
  throw (0, _dom.getConfig)().getElementError(`Unable to deselect an option in a non-multiple select. Use selectOptions to change the selection instead.`, select);
@@ -22,7 +24,7 @@ function selectOptionsBase(newValue, select, values, init) {
22
24
  if (allOptions.includes(val)) {
23
25
  return val;
24
26
  } else {
25
- const matchingOption = allOptions.find(o => o.value === val);
27
+ const matchingOption = allOptions.find(o => o.value === val || o.innerHTML === val);
26
28
 
27
29
  if (matchingOption) {
28
30
  return matchingOption;
@@ -70,15 +72,22 @@ function selectOptionsBase(newValue, select, values, init) {
70
72
  }
71
73
 
72
74
  function selectOption(option) {
73
- option.selected = newValue;
74
- (0, _dom.fireEvent)(select, (0, _dom.createEvent)('input', select, {
75
- bubbles: true,
76
- cancelable: false,
77
- composed: true,
78
- ...init
79
- }));
80
-
81
- _dom.fireEvent.change(select, init);
75
+ if (option.getAttribute('role') === 'option') {
76
+ option == null ? void 0 : option.setAttribute == null ? void 0 : option.setAttribute('aria-selected', newValue);
77
+ (0, _hover.hover)(option, init);
78
+ (0, _click.click)(option, init);
79
+ (0, _hover.unhover)(option, init);
80
+ } else {
81
+ option.selected = newValue;
82
+ (0, _dom.fireEvent)(select, (0, _dom.createEvent)('input', select, {
83
+ bubbles: true,
84
+ cancelable: false,
85
+ composed: true,
86
+ ...init
87
+ }));
88
+
89
+ _dom.fireEvent.change(select, init);
90
+ }
82
91
  }
83
92
  }
84
93
 
package/dist/type.js CHANGED
@@ -11,6 +11,8 @@ var _utils = require("./utils");
11
11
 
12
12
  var _click = require("./click");
13
13
 
14
+ var _navigationKey = require("./keys/navigation-key");
15
+
14
16
  // TODO: wrap in asyncWrapper
15
17
  const modifierCallbackMap = { ...createModifierCallbackEntries({
16
18
  name: 'shift',
@@ -38,6 +40,8 @@ const modifierCallbackMap = { ...createModifierCallbackEntries({
38
40
  })
39
41
  };
40
42
  const specialCharCallbackMap = {
43
+ '{arrowleft}': (0, _navigationKey.navigationKey)('ArrowLeft'),
44
+ '{arrowright}': (0, _navigationKey.navigationKey)('ArrowRight'),
41
45
  '{enter}': handleEnter,
42
46
  '{esc}': handleEsc,
43
47
  '{del}': handleDel,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "12.1.9",
3
+ "version": "12.2.2",
4
4
  "description": "Fire events the same way the user does",
5
5
  "main": "dist/index.js",
6
6
  "typings": "typings/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "homepage": "https://github.com/testing-library/user-event#readme",
27
27
  "files": [
28
28
  "dist",
29
- "typings"
29
+ "typings/index.d.ts"
30
30
  ],
31
31
  "scripts": {
32
32
  "build": "kcd-scripts build",
@@ -35,7 +35,8 @@
35
35
  "test": "kcd-scripts test",
36
36
  "test:debug": "kcd-scripts --inspect-brk test --runInBand",
37
37
  "test:update": "npm test -- --updateSnapshot --coverage",
38
- "validate": "kcd-scripts validate"
38
+ "validate": "kcd-scripts validate",
39
+ "typecheck": "tsc --project typings"
39
40
  },
40
41
  "dependencies": {
41
42
  "@babel/runtime": "^7.10.2"
@@ -43,9 +44,11 @@
43
44
  "devDependencies": {
44
45
  "@testing-library/dom": "^7.21.4",
45
46
  "@testing-library/jest-dom": "^5.11.1",
47
+ "@types/estree": "0.0.45",
46
48
  "is-ci": "^2.0.0",
47
49
  "jest-serializer-ansi": "^1.0.3",
48
- "kcd-scripts": "^6.2.3"
50
+ "kcd-scripts": "^6.2.3",
51
+ "typescript": "^4.0.5"
49
52
  },
50
53
  "peerDependencies": {
51
54
  "@testing-library/dom": ">=7.21.4"
@@ -53,11 +53,11 @@ declare const userEvent: {
53
53
  files: FilesArgument,
54
54
  init?: UploadInitArgument,
55
55
  ) => void
56
- type: (
56
+ type: <T extends ITypeOpts>(
57
57
  element: TargetElement,
58
58
  text: string,
59
- userOpts?: ITypeOpts,
60
- ) => Promise<void>
59
+ userOpts?: T,
60
+ ) => T extends {delay: number} ? Promise<void> : void
61
61
  tab: (userOpts?: ITabUserOptions) => void
62
62
  paste: (
63
63
  element: TargetElement,