@testing-library/user-event 14.0.0-alpha.10 → 14.0.0-alpha.11

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/dist/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
- import { specialCharMap } from './keyboard';
2
1
  import { UserEventApis, setup } from './setup';
3
2
  declare const userEvent: UserEventApis & {
4
3
  setup: typeof setup;
5
4
  };
6
5
  export default userEvent;
7
- export { specialCharMap as specialChars };
8
6
  export type { keyboardKey } from './keyboard';
package/dist/index.js CHANGED
@@ -4,14 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- Object.defineProperty(exports, "specialChars", {
8
- enumerable: true,
9
- get: function () {
10
- return _keyboard.specialCharMap;
11
- }
12
- });
13
-
14
- var _keyboard = require("./keyboard");
15
7
 
16
8
  var _setup = require("./setup");
17
9
 
@@ -6,8 +6,6 @@ export declare function getKeyEventProps(keyDef: keyboardKey, state: keyboardSta
6
6
  ctrlKey: boolean;
7
7
  metaKey: boolean;
8
8
  shiftKey: boolean;
9
- /** @deprecated use code instead */
10
- keyCode: number | undefined;
11
9
  };
12
10
  export declare function getMouseEventProps(state: keyboardState): {
13
11
  altKey: boolean;
@@ -7,19 +7,13 @@ exports.getKeyEventProps = getKeyEventProps;
7
7
  exports.getMouseEventProps = getMouseEventProps;
8
8
 
9
9
  function getKeyEventProps(keyDef, state) {
10
- var _keyDef$keyCode, _keyDef$key;
11
-
12
10
  return {
13
11
  key: keyDef.key,
14
12
  code: keyDef.code,
15
13
  altKey: state.modifiers.alt,
16
14
  ctrlKey: state.modifiers.ctrl,
17
15
  metaKey: state.modifiers.meta,
18
- shiftKey: state.modifiers.shift,
19
-
20
- /** @deprecated use code instead */
21
- keyCode: (_keyDef$keyCode = keyDef.keyCode) != null ? _keyDef$keyCode : // istanbul ignore next
22
- ((_keyDef$key = keyDef.key) == null ? void 0 : _keyDef$key.length) === 1 ? keyDef.key.charCodeAt(0) : undefined
16
+ shiftKey: state.modifiers.shift
23
17
  };
24
18
  }
25
19
 
@@ -1,5 +1,4 @@
1
1
  import { keyboardState, keyboardOptions, keyboardKey } from './types';
2
- export { specialCharMap } from './specialCharMap';
3
2
  export type { keyboardOptions, keyboardKey };
4
3
  export declare function keyboard(text: string, options?: Partial<keyboardOptions & {
5
4
  keyboardState: keyboardState;
@@ -6,12 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.createKeyboardState = createKeyboardState;
7
7
  exports.keyboard = keyboard;
8
8
  exports.keyboardImplementationWrapper = keyboardImplementationWrapper;
9
- Object.defineProperty(exports, "specialCharMap", {
10
- enumerable: true,
11
- get: function () {
12
- return _specialCharMap.specialCharMap;
13
- }
14
- });
15
9
 
16
10
  var _dom = require("@testing-library/dom");
17
11
 
@@ -21,8 +15,6 @@ var _keyboardImplementation = require("./keyboardImplementation");
21
15
 
22
16
  var _keyMap = require("./keyMap");
23
17
 
24
- var _specialCharMap = require("./specialCharMap");
25
-
26
18
  function keyboard(text, options) {
27
19
  var _options$delay;
28
20
 
@@ -32,112 +32,88 @@ const defaultKeyMap = [// alphanumeric keys
32
32
  }, {
33
33
  code: 'AltLeft',
34
34
  key: 'Alt',
35
- location: _types.DOM_KEY_LOCATION.LEFT,
36
- keyCode: 18
35
+ location: _types.DOM_KEY_LOCATION.LEFT
37
36
  }, {
38
37
  code: 'AltRight',
39
38
  key: 'Alt',
40
- location: _types.DOM_KEY_LOCATION.RIGHT,
41
- keyCode: 18
39
+ location: _types.DOM_KEY_LOCATION.RIGHT
42
40
  }, {
43
41
  code: 'ShiftLeft',
44
42
  key: 'Shift',
45
- location: _types.DOM_KEY_LOCATION.LEFT,
46
- keyCode: 16
43
+ location: _types.DOM_KEY_LOCATION.LEFT
47
44
  }, {
48
45
  code: 'ShiftRight',
49
46
  key: 'Shift',
50
- location: _types.DOM_KEY_LOCATION.RIGHT,
51
- keyCode: 16
47
+ location: _types.DOM_KEY_LOCATION.RIGHT
52
48
  }, {
53
49
  code: 'ControlLeft',
54
50
  key: 'Control',
55
- location: _types.DOM_KEY_LOCATION.LEFT,
56
- keyCode: 17
51
+ location: _types.DOM_KEY_LOCATION.LEFT
57
52
  }, {
58
53
  code: 'ControlRight',
59
54
  key: 'Control',
60
- location: _types.DOM_KEY_LOCATION.RIGHT,
61
- keyCode: 17
55
+ location: _types.DOM_KEY_LOCATION.RIGHT
62
56
  }, {
63
57
  code: 'MetaLeft',
64
58
  key: 'Meta',
65
- location: _types.DOM_KEY_LOCATION.LEFT,
66
- keyCode: 93
59
+ location: _types.DOM_KEY_LOCATION.LEFT
67
60
  }, {
68
61
  code: 'MetaRight',
69
62
  key: 'Meta',
70
- location: _types.DOM_KEY_LOCATION.RIGHT,
71
- keyCode: 93
63
+ location: _types.DOM_KEY_LOCATION.RIGHT
72
64
  }, {
73
65
  code: 'OSLeft',
74
66
  key: 'OS',
75
- location: _types.DOM_KEY_LOCATION.LEFT,
76
- keyCode: 91
67
+ location: _types.DOM_KEY_LOCATION.LEFT
77
68
  }, {
78
69
  code: 'OSRight',
79
70
  key: 'OS',
80
- location: _types.DOM_KEY_LOCATION.RIGHT,
81
- keyCode: 91
71
+ location: _types.DOM_KEY_LOCATION.RIGHT
82
72
  }, {
83
73
  code: 'Tab',
84
- key: 'Tab',
85
- keyCode: 9
74
+ key: 'Tab'
86
75
  }, {
87
76
  code: 'CapsLock',
88
- key: 'CapsLock',
89
- keyCode: 20
77
+ key: 'CapsLock'
90
78
  }, {
91
79
  code: 'Backspace',
92
- key: 'Backspace',
93
- keyCode: 8
80
+ key: 'Backspace'
94
81
  }, {
95
82
  code: 'Enter',
96
- key: 'Enter',
97
- keyCode: 13
83
+ key: 'Enter'
98
84
  }, // function
99
85
  {
100
86
  code: 'Escape',
101
- key: 'Escape',
102
- keyCode: 27
87
+ key: 'Escape'
103
88
  }, // arrows
104
89
  {
105
90
  code: 'ArrowUp',
106
- key: 'ArrowUp',
107
- keyCode: 38
91
+ key: 'ArrowUp'
108
92
  }, {
109
93
  code: 'ArrowDown',
110
- key: 'ArrowDown',
111
- keyCode: 40
94
+ key: 'ArrowDown'
112
95
  }, {
113
96
  code: 'ArrowLeft',
114
- key: 'ArrowLeft',
115
- keyCode: 37
97
+ key: 'ArrowLeft'
116
98
  }, {
117
99
  code: 'ArrowRight',
118
- key: 'ArrowRight',
119
- keyCode: 39
100
+ key: 'ArrowRight'
120
101
  }, // control pad
121
102
  {
122
103
  code: 'Home',
123
- key: 'Home',
124
- keyCode: 36
104
+ key: 'Home'
125
105
  }, {
126
106
  code: 'End',
127
- key: 'End',
128
- keyCode: 35
107
+ key: 'End'
129
108
  }, {
130
109
  code: 'Delete',
131
- key: 'Delete',
132
- keyCode: 46
110
+ key: 'Delete'
133
111
  }, {
134
112
  code: 'PageUp',
135
- key: 'PageUp',
136
- keyCode: 33
113
+ key: 'PageUp'
137
114
  }, {
138
115
  code: 'PageDown',
139
- key: 'PageDown',
140
- keyCode: 34
116
+ key: 'PageDown'
141
117
  } // TODO: add mappings
142
118
  ];
143
119
  exports.defaultKeyMap = defaultKeyMap;
@@ -36,27 +36,23 @@ async function keyboardImplementation(text, options, state) {
36
36
  releaseSelf,
37
37
  repeat
38
38
  } = (_state$repeatKey = state.repeatKey) != null ? _state$repeatKey : (0, _getNextKeyDef.getNextKeyDef)(text, options);
39
- const replace = applyPlugins(plugins.replaceBehavior, keyDef, getCurrentElement(), options, state);
39
+ const pressed = state.pressed.find(p => p.keyDef === keyDef); // Release the key automatically if it was pressed before.
40
+ // Do not release the key on iterations on `state.repeatKey`.
40
41
 
41
- if (!replace) {
42
- const pressed = state.pressed.find(p => p.keyDef === keyDef); // Release the key automatically if it was pressed before.
43
- // Do not release the key on iterations on `state.repeatKey`.
44
-
45
- if (pressed && !state.repeatKey) {
46
- keyup(keyDef, getCurrentElement, options, state, pressed.unpreventedDefault);
47
- }
42
+ if (pressed && !state.repeatKey) {
43
+ keyup(keyDef, getCurrentElement, options, state, pressed.unpreventedDefault);
44
+ }
48
45
 
49
- if (!releasePrevious) {
50
- const unpreventedDefault = keydown(keyDef, getCurrentElement, options, state);
46
+ if (!releasePrevious) {
47
+ const unpreventedDefault = keydown(keyDef, getCurrentElement, options, state);
51
48
 
52
- if (unpreventedDefault && hasKeyPress(keyDef, state)) {
53
- keypress(keyDef, getCurrentElement, options, state);
54
- } // Release the key only on the last iteration on `state.repeatKey`.
49
+ if (unpreventedDefault && hasKeyPress(keyDef, state)) {
50
+ keypress(keyDef, getCurrentElement, options, state);
51
+ } // Release the key only on the last iteration on `state.repeatKey`.
55
52
 
56
53
 
57
- if (releaseSelf && repeat <= 1) {
58
- keyup(keyDef, getCurrentElement, options, state, unpreventedDefault);
59
- }
54
+ if (releaseSelf && repeat <= 1) {
55
+ keyup(keyDef, getCurrentElement, options, state, unpreventedDefault);
60
56
  }
61
57
  }
62
58
 
@@ -1,5 +1,4 @@
1
1
  import { behaviorPlugin } from '../types';
2
- export declare const replaceBehavior: behaviorPlugin[];
3
2
  export declare const preKeydownBehavior: behaviorPlugin[];
4
3
  export declare const keydownBehavior: behaviorPlugin[];
5
4
  export declare const keypressBehavior: behaviorPlugin[];
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.replaceBehavior = exports.preKeyupBehavior = exports.preKeydownBehavior = exports.postKeyupBehavior = exports.keyupBehavior = exports.keypressBehavior = exports.keydownBehavior = void 0;
7
-
8
- var _utils = require("../../utils");
6
+ exports.preKeyupBehavior = exports.preKeydownBehavior = exports.postKeyupBehavior = exports.keyupBehavior = exports.keypressBehavior = exports.keydownBehavior = void 0;
9
7
 
10
8
  var arrowKeys = _interopRequireWildcard(require("./arrow"));
11
9
 
@@ -21,13 +19,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
21
19
 
22
20
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
21
 
24
- const replaceBehavior = [{
25
- matches: (keyDef, element) => keyDef.key === 'selectall' && (0, _utils.isElementType)(element, ['input', 'textarea']),
26
- handle: (keyDef, element) => {
27
- (0, _utils.setSelectionRange)(element, 0, (0, _utils.getValue)(element).length);
28
- }
29
- }];
30
- exports.replaceBehavior = replaceBehavior;
31
22
  const preKeydownBehavior = [...functionalKeys.preKeydownBehavior];
32
23
  exports.preKeydownBehavior = preKeydownBehavior;
33
24
  const keydownBehavior = [...arrowKeys.keydownBehavior, ...controlKeys.keydownBehavior, ...functionalKeys.keydownBehavior, ...combination.keydownBehavior];
@@ -67,8 +67,6 @@ export interface keyboardKey {
67
67
  key?: string;
68
68
  /** Location on the keyboard for keys with multiple representation */
69
69
  location?: DOM_KEY_LOCATION;
70
- /** keyCode for legacy support */
71
- keyCode?: number;
72
70
  /** Does the character in `key` require/imply AltRight to be pressed? */
73
71
  altGr?: boolean;
74
72
  /** Does the character in `key` require/imply a shiftKey to be pressed? */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.0.0-alpha.10",
3
+ "version": "14.0.0-alpha.11",
4
4
  "description": "Fire events the same way the user does",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [
@@ -1,22 +0,0 @@
1
- /**
2
- * @deprecated This list of strings with special meaning is no longer necessary
3
- * as we've introduced a standardized way to describe any keystroke for `userEvent`.
4
- * @see https://testing-library.com/docs/ecosystem-user-event#keyboardtext-options
5
- */
6
- export declare const specialCharMap: {
7
- readonly arrowLeft: "{arrowleft}";
8
- readonly arrowRight: "{arrowright}";
9
- readonly arrowDown: "{arrowdown}";
10
- readonly arrowUp: "{arrowup}";
11
- readonly enter: "{enter}";
12
- readonly escape: "{esc}";
13
- readonly delete: "{del}";
14
- readonly backspace: "{backspace}";
15
- readonly home: "{home}";
16
- readonly end: "{end}";
17
- readonly selectAll: "{selectall}";
18
- readonly space: "{space}";
19
- readonly whitespace: " ";
20
- readonly pageUp: "{pageUp}";
21
- readonly pageDown: "{pageDown}";
22
- };
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.specialCharMap = void 0;
7
-
8
- /**
9
- * @deprecated This list of strings with special meaning is no longer necessary
10
- * as we've introduced a standardized way to describe any keystroke for `userEvent`.
11
- * @see https://testing-library.com/docs/ecosystem-user-event#keyboardtext-options
12
- */
13
- const specialCharMap = {
14
- arrowLeft: '{arrowleft}',
15
- arrowRight: '{arrowright}',
16
- arrowDown: '{arrowdown}',
17
- arrowUp: '{arrowup}',
18
- enter: '{enter}',
19
- escape: '{esc}',
20
- delete: '{del}',
21
- backspace: '{backspace}',
22
- home: '{home}',
23
- end: '{end}',
24
- selectAll: '{selectall}',
25
- space: '{space}',
26
- whitespace: ' ',
27
- pageUp: '{pageUp}',
28
- pageDown: '{pageDown}'
29
- };
30
- exports.specialCharMap = specialCharMap;