@testing-library/user-event 12.2.2 → 12.3.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 CHANGED
@@ -89,11 +89,16 @@ import userEvent from '@testing-library/user-event'
89
89
 
90
90
  // or
91
91
 
92
- var userEvent = require('@testing-library/user-event')
92
+ const {default: userEvent} = require('@testing-library/user-event')
93
93
  ```
94
94
 
95
95
  ## API
96
96
 
97
+ Note: All userEvent methods are synchronous with one exception: when `delay`
98
+ with `userEvent.type` as described below). We also discourage using `userEvent`
99
+ inside `before/after` blocks at all, for important reasons described in
100
+ ["Avoid Nesting When You're Testing"](https://kentcdodds.com/blog/avoid-nesting-when-youre-testing).
101
+
97
102
  ### `click(element, eventInit, options)`
98
103
 
99
104
  Clicks `element`, depending on what `element` is it can have different side
@@ -183,20 +188,21 @@ to `await`!
183
188
 
184
189
  The following special character strings are supported:
185
190
 
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` | |
191
+ | Text string | Key | Modifier | Notes |
192
+ | -------------- | ---------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
193
+ | `{enter}` | Enter | N/A | Will insert a newline character (`<textarea />` only). |
194
+ | `{space}` | `' '` | N/A | |
195
+ | `{esc}` | Escape | N/A | |
196
+ | `{backspace}` | Backspace | N/A | Will delete the previous character (or the characters within the `selectedRange`, see example below). |
197
+ | `{del}` | Delete | N/A | Will delete the next character (or the characters within the `selectedRange`, see example below) |
198
+ | `{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) |
199
+ | `{arrowleft}` | ArrowLeft | N/A | |
200
+ | `{arrowright}` | ArrowRight | N/A | |
201
+ | `{shift}` | Shift | `shiftKey` | Does **not** capitalize following characters. |
202
+ | `{ctrl}` | Control | `ctrlKey` | |
203
+ | `{alt}` | Alt | `altKey` | |
204
+ | `{meta}` | OS | `metaKey` | |
205
+ | `{capslock}` | CapsLock | `modifierCapsLock` | Fires both keydown and keyup when used (simulates a user clicking their "Caps Lock" button to enable caps lock). |
200
206
 
201
207
  > **A note about modifiers:** Modifier keys (`{shift}`, `{ctrl}`, `{alt}`,
202
208
  > `{meta}`) will activate their corresponding event modifiers for the duration
@@ -597,6 +603,8 @@ Thanks goes to these people ([emoji key][emojis]):
597
603
  <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
604
  <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
605
  <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>
606
+ <td align="center"><a href="https://github.com/amandapouget"><img src="https://avatars3.githubusercontent.com/u/12855692?v=4" width="100px;" alt=""/><br /><sub><b>Amanda Pouget</b></sub></a><br /><a href="https://github.com/testing-library/user-event/commits?author=amandapouget" title="Documentation">📖</a></td>
607
+ <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>
600
608
  </tr>
601
609
  </table>
602
610
 
package/dist/click.js CHANGED
@@ -88,7 +88,7 @@ function clickElement(element, init, {
88
88
  _dom.fireEvent.click(element, (0, _utils.getMouseEventOptions)('click', init, clickCount));
89
89
 
90
90
  const parentLabel = element.closest('label');
91
- if (parentLabel == null ? void 0 : parentLabel.control) (0, _focus.focus)(parentLabel.control, init);
91
+ if (parentLabel != null && parentLabel.control) (0, _focus.focus)(parentLabel.control, init);
92
92
  }
93
93
  }
94
94
 
package/dist/type.js CHANGED
@@ -37,7 +37,64 @@ const modifierCallbackMap = { ...createModifierCallbackEntries({
37
37
  key: 'Meta',
38
38
  keyCode: 93,
39
39
  modifierProperty: 'metaKey'
40
- })
40
+ }),
41
+ // capslock is inline because of the need to fire both keydown and keyup on use, while preserving the modifier state.
42
+ '{capslock}': function ({
43
+ currentElement,
44
+ eventOverrides
45
+ }) {
46
+ const newEventOverrides = {
47
+ modifierCapsLock: true
48
+ };
49
+
50
+ _dom.fireEvent.keyDown(currentElement(), {
51
+ key: 'CapsLock',
52
+ keyCode: 20,
53
+ which: 20,
54
+ ...eventOverrides,
55
+ ...newEventOverrides
56
+ });
57
+
58
+ _dom.fireEvent.keyUp(currentElement(), {
59
+ key: 'CapsLock',
60
+ keyCode: 20,
61
+ which: 20,
62
+ ...eventOverrides,
63
+ ...newEventOverrides
64
+ });
65
+
66
+ return {
67
+ eventOverrides: newEventOverrides
68
+ };
69
+ },
70
+ '{/capslock}': function ({
71
+ currentElement,
72
+ eventOverrides
73
+ }) {
74
+ const newEventOverrides = {
75
+ modifierCapsLock: false
76
+ };
77
+
78
+ _dom.fireEvent.keyDown(currentElement(), {
79
+ key: 'CapsLock',
80
+ keyCode: 20,
81
+ which: 20,
82
+ ...eventOverrides,
83
+ ...newEventOverrides
84
+ });
85
+
86
+ _dom.fireEvent.keyUp(currentElement(), {
87
+ key: 'CapsLock',
88
+ keyCode: 20,
89
+ which: 20,
90
+ ...eventOverrides,
91
+ ...newEventOverrides
92
+ });
93
+
94
+ return {
95
+ eventOverrides: newEventOverrides
96
+ };
97
+ }
41
98
  };
42
99
  const specialCharCallbackMap = {
43
100
  '{arrowleft}': (0, _navigationKey.navigationKey)('ArrowLeft'),
package/dist/utils.js CHANGED
@@ -95,7 +95,7 @@ function isLabelWithInternallyDisabledControl(element) {
95
95
  function getActiveElement(document) {
96
96
  const activeElement = document.activeElement;
97
97
 
98
- if (activeElement == null ? void 0 : activeElement.shadowRoot) {
98
+ if (activeElement != null && activeElement.shadowRoot) {
99
99
  return getActiveElement(activeElement.shadowRoot);
100
100
  } else {
101
101
  return activeElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "12.2.2",
3
+ "version": "12.3.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",