@testing-library/user-event 14.0.0-beta.6 → 14.0.0-beta.7
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.cjs +189 -144
- package/dist/index.mjs +189 -144
- package/dist/types/clipboard/copy.d.ts +2 -2
- package/dist/types/clipboard/cut.d.ts +2 -2
- package/dist/types/clipboard/paste.d.ts +2 -2
- package/dist/types/convenience/click.d.ts +4 -4
- package/dist/types/convenience/hover.d.ts +3 -3
- package/dist/types/convenience/tab.d.ts +2 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/keyboard/index.d.ts +2 -2
- package/dist/types/options.d.ts +23 -8
- package/dist/types/pointer/index.d.ts +2 -2
- package/dist/types/pointer/pointerMove.d.ts +2 -2
- package/dist/types/pointer/pointerPress.d.ts +2 -2
- package/dist/types/setup/directApi.d.ts +1 -2
- package/dist/types/setup/index.d.ts +6 -2
- package/dist/types/setup/setup.d.ts +5 -60
- package/dist/types/utility/clear.d.ts +2 -2
- package/dist/types/utility/selectOptions.d.ts +3 -3
- package/dist/types/utility/type.d.ts +2 -2
- package/dist/types/utility/upload.d.ts +2 -2
- package/dist/types/utils/index.d.ts +2 -1
- package/dist/types/utils/misc/level.d.ts +17 -0
- package/dist/types/utils/pointer/cssPointerEvents.d.ts +15 -0
- package/package.json +1 -1
- package/dist/types/utils/misc/hasPointerEvents.d.ts +0 -15
package/dist/index.mjs
CHANGED
|
@@ -1325,13 +1325,121 @@ function isDescendantOrSelf(potentialDescendant, potentialAncestor) {
|
|
|
1325
1325
|
return false;
|
|
1326
1326
|
}
|
|
1327
1327
|
|
|
1328
|
+
// src/utils/misc/level.ts
|
|
1329
|
+
var Level = Symbol("Api level refs");
|
|
1330
|
+
function setLevelRef(config, level) {
|
|
1331
|
+
var _a;
|
|
1332
|
+
(_a = config[Level]) != null ? _a : config[Level] = {};
|
|
1333
|
+
config[Level][level] = {};
|
|
1334
|
+
}
|
|
1335
|
+
function getLevelRef(config, level) {
|
|
1336
|
+
var _a;
|
|
1337
|
+
return (_a = config[Level]) == null ? void 0 : _a[level];
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1328
1340
|
// src/utils/misc/wait.ts
|
|
1329
1341
|
function wait(time) {
|
|
1330
1342
|
return new Promise((resolve) => setTimeout(() => resolve(), time));
|
|
1331
1343
|
}
|
|
1332
1344
|
|
|
1333
|
-
// src/utils/misc/
|
|
1345
|
+
// src/utils/misc/hasFormSubmit.ts
|
|
1346
|
+
var hasFormSubmit = (form) => !!(form == null ? void 0 : form.querySelector('input[type="submit"], button:not([type]), button[type="submit"]'));
|
|
1347
|
+
|
|
1348
|
+
// src/utils/pointer/cssPointerEvents.ts
|
|
1334
1349
|
import { getWindowFromNode as getWindowFromNode2 } from "@testing-library/dom/dist/helpers.js";
|
|
1350
|
+
|
|
1351
|
+
// src/keyboard/keyMap.ts
|
|
1352
|
+
var defaultKeyMap = [
|
|
1353
|
+
..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
|
|
1354
|
+
...")!@#$%^&*(".split("").map((c, i) => ({ code: `Digit${i}`, key: c, shiftKey: true })),
|
|
1355
|
+
..."abcdefghijklmnopqrstuvwxyz".split("").map((c) => ({ code: `Key${c.toUpperCase()}`, key: c })),
|
|
1356
|
+
..."ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("").map((c) => ({ code: `Key${c}`, key: c, shiftKey: true })),
|
|
1357
|
+
{ code: "Space", key: " " },
|
|
1358
|
+
{ code: "AltLeft", key: "Alt", location: 1 /* LEFT */ },
|
|
1359
|
+
{ code: "AltRight", key: "Alt", location: 2 /* RIGHT */ },
|
|
1360
|
+
{
|
|
1361
|
+
code: "ShiftLeft",
|
|
1362
|
+
key: "Shift",
|
|
1363
|
+
location: 1 /* LEFT */
|
|
1364
|
+
},
|
|
1365
|
+
{
|
|
1366
|
+
code: "ShiftRight",
|
|
1367
|
+
key: "Shift",
|
|
1368
|
+
location: 2 /* RIGHT */
|
|
1369
|
+
},
|
|
1370
|
+
{
|
|
1371
|
+
code: "ControlLeft",
|
|
1372
|
+
key: "Control",
|
|
1373
|
+
location: 1 /* LEFT */
|
|
1374
|
+
},
|
|
1375
|
+
{
|
|
1376
|
+
code: "ControlRight",
|
|
1377
|
+
key: "Control",
|
|
1378
|
+
location: 2 /* RIGHT */
|
|
1379
|
+
},
|
|
1380
|
+
{ code: "MetaLeft", key: "Meta", location: 1 /* LEFT */ },
|
|
1381
|
+
{
|
|
1382
|
+
code: "MetaRight",
|
|
1383
|
+
key: "Meta",
|
|
1384
|
+
location: 2 /* RIGHT */
|
|
1385
|
+
},
|
|
1386
|
+
{ code: "OSLeft", key: "OS", location: 1 /* LEFT */ },
|
|
1387
|
+
{ code: "OSRight", key: "OS", location: 2 /* RIGHT */ },
|
|
1388
|
+
{ code: "Tab", key: "Tab" },
|
|
1389
|
+
{ code: "CapsLock", key: "CapsLock" },
|
|
1390
|
+
{ code: "Backspace", key: "Backspace" },
|
|
1391
|
+
{ code: "Enter", key: "Enter" },
|
|
1392
|
+
{ code: "Escape", key: "Escape" },
|
|
1393
|
+
{ code: "ArrowUp", key: "ArrowUp" },
|
|
1394
|
+
{ code: "ArrowDown", key: "ArrowDown" },
|
|
1395
|
+
{ code: "ArrowLeft", key: "ArrowLeft" },
|
|
1396
|
+
{ code: "ArrowRight", key: "ArrowRight" },
|
|
1397
|
+
{ code: "Home", key: "Home" },
|
|
1398
|
+
{ code: "End", key: "End" },
|
|
1399
|
+
{ code: "Delete", key: "Delete" },
|
|
1400
|
+
{ code: "PageUp", key: "PageUp" },
|
|
1401
|
+
{ code: "PageDown", key: "PageDown" },
|
|
1402
|
+
{ code: "Fn", key: "Fn" },
|
|
1403
|
+
{ code: "Symbol", key: "Symbol" },
|
|
1404
|
+
{ code: "AltRight", key: "AltGraph" }
|
|
1405
|
+
];
|
|
1406
|
+
|
|
1407
|
+
// src/pointer/keyMap.ts
|
|
1408
|
+
var defaultKeyMap2 = [
|
|
1409
|
+
{ name: "MouseLeft", pointerType: "mouse", button: "primary" },
|
|
1410
|
+
{ name: "MouseRight", pointerType: "mouse", button: "secondary" },
|
|
1411
|
+
{ name: "MouseMiddle", pointerType: "mouse", button: "auxiliary" },
|
|
1412
|
+
{ name: "TouchA", pointerType: "touch" },
|
|
1413
|
+
{ name: "TouchB", pointerType: "touch" },
|
|
1414
|
+
{ name: "TouchC", pointerType: "touch" }
|
|
1415
|
+
];
|
|
1416
|
+
|
|
1417
|
+
// src/options.ts
|
|
1418
|
+
var PointerEventsCheckLevel = /* @__PURE__ */ ((PointerEventsCheckLevel2) => {
|
|
1419
|
+
PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachTrigger"] = 4] = "EachTrigger";
|
|
1420
|
+
PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachApiCall"] = 2] = "EachApiCall";
|
|
1421
|
+
PointerEventsCheckLevel2[PointerEventsCheckLevel2["EachTarget"] = 1] = "EachTarget";
|
|
1422
|
+
PointerEventsCheckLevel2[PointerEventsCheckLevel2["Never"] = 0] = "Never";
|
|
1423
|
+
return PointerEventsCheckLevel2;
|
|
1424
|
+
})(PointerEventsCheckLevel || {});
|
|
1425
|
+
var defaultOptionsDirect = {
|
|
1426
|
+
applyAccept: true,
|
|
1427
|
+
autoModify: true,
|
|
1428
|
+
delay: 0,
|
|
1429
|
+
document: global.document,
|
|
1430
|
+
keyboardMap: defaultKeyMap,
|
|
1431
|
+
pointerMap: defaultKeyMap2,
|
|
1432
|
+
pointerEventsCheck: 2 /* EachApiCall */,
|
|
1433
|
+
skipAutoClose: false,
|
|
1434
|
+
skipClick: false,
|
|
1435
|
+
skipHover: false,
|
|
1436
|
+
writeToClipboard: false
|
|
1437
|
+
};
|
|
1438
|
+
var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect), {
|
|
1439
|
+
writeToClipboard: true
|
|
1440
|
+
});
|
|
1441
|
+
|
|
1442
|
+
// src/utils/pointer/cssPointerEvents.ts
|
|
1335
1443
|
function hasPointerEvents(element) {
|
|
1336
1444
|
const window2 = getWindowFromNode2(element);
|
|
1337
1445
|
for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
|
|
@@ -1342,9 +1450,26 @@ function hasPointerEvents(element) {
|
|
|
1342
1450
|
}
|
|
1343
1451
|
return true;
|
|
1344
1452
|
}
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1453
|
+
var PointerEventsCheck = Symbol("Last check for pointer-events");
|
|
1454
|
+
function assertPointerEvents(config, element) {
|
|
1455
|
+
const lastCheck = element[PointerEventsCheck];
|
|
1456
|
+
const needsCheck = config.pointerEventsCheck !== 0 /* Never */ && (!lastCheck || hasBitFlag(config.pointerEventsCheck, 2 /* EachApiCall */) && lastCheck[1 /* Call */] !== getLevelRef(config, 1 /* Call */) || hasBitFlag(config.pointerEventsCheck, 4 /* EachTrigger */) && lastCheck[2 /* Trigger */] !== getLevelRef(config, 2 /* Trigger */));
|
|
1457
|
+
if (!needsCheck) {
|
|
1458
|
+
return;
|
|
1459
|
+
}
|
|
1460
|
+
const result = hasPointerEvents(element);
|
|
1461
|
+
element[PointerEventsCheck] = {
|
|
1462
|
+
[1 /* Call */]: getLevelRef(config, 1 /* Call */),
|
|
1463
|
+
[2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
|
|
1464
|
+
result
|
|
1465
|
+
};
|
|
1466
|
+
if (!result) {
|
|
1467
|
+
throw new Error('Unable to perform pointer interaction as the element has or inherits pointer-events set to "none".');
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
function hasBitFlag(conf, flag) {
|
|
1471
|
+
return (conf & flag) > 0;
|
|
1472
|
+
}
|
|
1348
1473
|
|
|
1349
1474
|
// src/utils/pointer/firePointerEvents.ts
|
|
1350
1475
|
import { createEvent, fireEvent as fireEvent4 } from "@testing-library/dom";
|
|
@@ -2029,7 +2154,8 @@ function findNodeAtTextOffset(node, offset, isRoot = true) {
|
|
|
2029
2154
|
|
|
2030
2155
|
// src/pointer/pointerMove.ts
|
|
2031
2156
|
function pointerMove(_0, _1) {
|
|
2032
|
-
return __async(this, arguments, function* ({ pointerName = "mouse", target, coords, node, offset }
|
|
2157
|
+
return __async(this, arguments, function* (config, { pointerName = "mouse", target, coords, node, offset }) {
|
|
2158
|
+
const { pointerState, keyboardState } = config;
|
|
2033
2159
|
if (!(pointerName in pointerState.position)) {
|
|
2034
2160
|
throw new Error(`Trying to move pointer "${pointerName}" which does not exist.`);
|
|
2035
2161
|
}
|
|
@@ -2041,11 +2167,15 @@ function pointerMove(_0, _1) {
|
|
|
2041
2167
|
selectionRange
|
|
2042
2168
|
} = pointerState.position[pointerName];
|
|
2043
2169
|
if (prevTarget && prevTarget !== target) {
|
|
2170
|
+
setLevelRef(config, 2 /* Trigger */);
|
|
2171
|
+
assertPointerEvents(config, prevTarget);
|
|
2044
2172
|
fireMove(prevTarget, prevCoords);
|
|
2045
2173
|
if (!isDescendantOrSelf(target, prevTarget)) {
|
|
2046
2174
|
fireLeave(prevTarget, prevCoords);
|
|
2047
2175
|
}
|
|
2048
2176
|
}
|
|
2177
|
+
setLevelRef(config, 2 /* Trigger */);
|
|
2178
|
+
assertPointerEvents(config, target);
|
|
2049
2179
|
pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
|
|
2050
2180
|
target,
|
|
2051
2181
|
coords
|
|
@@ -2112,19 +2242,19 @@ function pointerMove(_0, _1) {
|
|
|
2112
2242
|
}
|
|
2113
2243
|
|
|
2114
2244
|
// src/pointer/pointerPress.ts
|
|
2115
|
-
function pointerPress(
|
|
2245
|
+
function pointerPress(config, action) {
|
|
2116
2246
|
return __async(this, null, function* () {
|
|
2117
2247
|
const { keyDef, target, releasePrevious, releaseSelf } = action;
|
|
2118
|
-
const previous =
|
|
2248
|
+
const previous = config.pointerState.pressed.find((p) => p.keyDef === keyDef);
|
|
2119
2249
|
const pointerName = keyDef.pointerType === "touch" ? keyDef.name : keyDef.pointerType;
|
|
2120
2250
|
const targetIsDisabled = isDisabled(target);
|
|
2121
2251
|
if (previous) {
|
|
2122
|
-
up(
|
|
2252
|
+
up(config, pointerName, action, previous, targetIsDisabled);
|
|
2123
2253
|
}
|
|
2124
2254
|
if (!releasePrevious) {
|
|
2125
|
-
const press = down(
|
|
2255
|
+
const press = down(config, pointerName, action, targetIsDisabled);
|
|
2126
2256
|
if (releaseSelf) {
|
|
2127
|
-
up(
|
|
2257
|
+
up(config, pointerName, action, press, targetIsDisabled);
|
|
2128
2258
|
}
|
|
2129
2259
|
}
|
|
2130
2260
|
});
|
|
@@ -2133,8 +2263,11 @@ function getNextPointerId(state) {
|
|
|
2133
2263
|
state.pointerId = state.pointerId + 1;
|
|
2134
2264
|
return state.pointerId;
|
|
2135
2265
|
}
|
|
2136
|
-
function down(
|
|
2266
|
+
function down(config, pointerName, { keyDef, node, offset, target, coords }, targetIsDisabled) {
|
|
2137
2267
|
var _a, _b, _c;
|
|
2268
|
+
setLevelRef(config, 2 /* Trigger */);
|
|
2269
|
+
assertPointerEvents(config, target);
|
|
2270
|
+
const { pointerState, keyboardState } = config;
|
|
2138
2271
|
const { name, pointerType, button } = keyDef;
|
|
2139
2272
|
const pointerId = pointerType === "mouse" ? 1 : getNextPointerId(pointerState);
|
|
2140
2273
|
pointerState.position[pointerName] = __spreadProps(__spreadValues({}, pointerState.position[pointerName]), {
|
|
@@ -2208,7 +2341,7 @@ function down({ pointerState, keyboardState }, pointerName, { keyDef, node, offs
|
|
|
2208
2341
|
});
|
|
2209
2342
|
}
|
|
2210
2343
|
}
|
|
2211
|
-
function up(
|
|
2344
|
+
function up(config, pointerName, {
|
|
2212
2345
|
keyDef: { pointerType, button },
|
|
2213
2346
|
target,
|
|
2214
2347
|
coords,
|
|
@@ -2216,6 +2349,9 @@ function up({ pointerState, keyboardState }, pointerName, {
|
|
|
2216
2349
|
offset
|
|
2217
2350
|
}, pressed, targetIsDisabled) {
|
|
2218
2351
|
var _a;
|
|
2352
|
+
setLevelRef(config, 2 /* Trigger */);
|
|
2353
|
+
assertPointerEvents(config, target);
|
|
2354
|
+
const { pointerState, keyboardState } = config;
|
|
2219
2355
|
pointerState.pressed = pointerState.pressed.filter((p) => p !== pressed);
|
|
2220
2356
|
const { isMultiTouch, isPrimary, pointerId, clickCount } = pressed;
|
|
2221
2357
|
let { unpreventedDefault } = pressed;
|
|
@@ -2351,7 +2487,7 @@ function pointerAction(config, actions) {
|
|
|
2351
2487
|
const pointerName = "pointerName" in action && action.pointerName ? action.pointerName : "keyDef" in action ? action.keyDef.pointerType === "touch" ? action.keyDef.name : action.keyDef.pointerType : "mouse";
|
|
2352
2488
|
const target = (_a = action.target) != null ? _a : getPrevTarget(pointerName, config.pointerState);
|
|
2353
2489
|
const coords = (_b = action.coords) != null ? _b : pointerName in config.pointerState.position ? config.pointerState.position[pointerName].coords : void 0;
|
|
2354
|
-
yield "keyDef" in action ? pointerPress(__spreadProps(__spreadValues({}, action), { target, coords })
|
|
2490
|
+
yield "keyDef" in action ? pointerPress(config, __spreadProps(__spreadValues({}, action), { target, coords })) : pointerMove(config, __spreadProps(__spreadValues({}, action), { target, coords }));
|
|
2355
2491
|
if (typeof config.delay === "number") {
|
|
2356
2492
|
if (i < actions.length - 1) {
|
|
2357
2493
|
yield wait(config.delay);
|
|
@@ -2409,90 +2545,6 @@ function createPointerState(document2) {
|
|
|
2409
2545
|
};
|
|
2410
2546
|
}
|
|
2411
2547
|
|
|
2412
|
-
// src/keyboard/keyMap.ts
|
|
2413
|
-
var defaultKeyMap = [
|
|
2414
|
-
..."0123456789".split("").map((c) => ({ code: `Digit${c}`, key: c })),
|
|
2415
|
-
...")!@#$%^&*(".split("").map((c, i) => ({ code: `Digit${i}`, key: c, shiftKey: true })),
|
|
2416
|
-
..."abcdefghijklmnopqrstuvwxyz".split("").map((c) => ({ code: `Key${c.toUpperCase()}`, key: c })),
|
|
2417
|
-
..."ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("").map((c) => ({ code: `Key${c}`, key: c, shiftKey: true })),
|
|
2418
|
-
{ code: "Space", key: " " },
|
|
2419
|
-
{ code: "AltLeft", key: "Alt", location: 1 /* LEFT */ },
|
|
2420
|
-
{ code: "AltRight", key: "Alt", location: 2 /* RIGHT */ },
|
|
2421
|
-
{
|
|
2422
|
-
code: "ShiftLeft",
|
|
2423
|
-
key: "Shift",
|
|
2424
|
-
location: 1 /* LEFT */
|
|
2425
|
-
},
|
|
2426
|
-
{
|
|
2427
|
-
code: "ShiftRight",
|
|
2428
|
-
key: "Shift",
|
|
2429
|
-
location: 2 /* RIGHT */
|
|
2430
|
-
},
|
|
2431
|
-
{
|
|
2432
|
-
code: "ControlLeft",
|
|
2433
|
-
key: "Control",
|
|
2434
|
-
location: 1 /* LEFT */
|
|
2435
|
-
},
|
|
2436
|
-
{
|
|
2437
|
-
code: "ControlRight",
|
|
2438
|
-
key: "Control",
|
|
2439
|
-
location: 2 /* RIGHT */
|
|
2440
|
-
},
|
|
2441
|
-
{ code: "MetaLeft", key: "Meta", location: 1 /* LEFT */ },
|
|
2442
|
-
{
|
|
2443
|
-
code: "MetaRight",
|
|
2444
|
-
key: "Meta",
|
|
2445
|
-
location: 2 /* RIGHT */
|
|
2446
|
-
},
|
|
2447
|
-
{ code: "OSLeft", key: "OS", location: 1 /* LEFT */ },
|
|
2448
|
-
{ code: "OSRight", key: "OS", location: 2 /* RIGHT */ },
|
|
2449
|
-
{ code: "Tab", key: "Tab" },
|
|
2450
|
-
{ code: "CapsLock", key: "CapsLock" },
|
|
2451
|
-
{ code: "Backspace", key: "Backspace" },
|
|
2452
|
-
{ code: "Enter", key: "Enter" },
|
|
2453
|
-
{ code: "Escape", key: "Escape" },
|
|
2454
|
-
{ code: "ArrowUp", key: "ArrowUp" },
|
|
2455
|
-
{ code: "ArrowDown", key: "ArrowDown" },
|
|
2456
|
-
{ code: "ArrowLeft", key: "ArrowLeft" },
|
|
2457
|
-
{ code: "ArrowRight", key: "ArrowRight" },
|
|
2458
|
-
{ code: "Home", key: "Home" },
|
|
2459
|
-
{ code: "End", key: "End" },
|
|
2460
|
-
{ code: "Delete", key: "Delete" },
|
|
2461
|
-
{ code: "PageUp", key: "PageUp" },
|
|
2462
|
-
{ code: "PageDown", key: "PageDown" },
|
|
2463
|
-
{ code: "Fn", key: "Fn" },
|
|
2464
|
-
{ code: "Symbol", key: "Symbol" },
|
|
2465
|
-
{ code: "AltRight", key: "AltGraph" }
|
|
2466
|
-
];
|
|
2467
|
-
|
|
2468
|
-
// src/pointer/keyMap.ts
|
|
2469
|
-
var defaultKeyMap2 = [
|
|
2470
|
-
{ name: "MouseLeft", pointerType: "mouse", button: "primary" },
|
|
2471
|
-
{ name: "MouseRight", pointerType: "mouse", button: "secondary" },
|
|
2472
|
-
{ name: "MouseMiddle", pointerType: "mouse", button: "auxiliary" },
|
|
2473
|
-
{ name: "TouchA", pointerType: "touch" },
|
|
2474
|
-
{ name: "TouchB", pointerType: "touch" },
|
|
2475
|
-
{ name: "TouchC", pointerType: "touch" }
|
|
2476
|
-
];
|
|
2477
|
-
|
|
2478
|
-
// src/options.ts
|
|
2479
|
-
var defaultOptionsDirect = {
|
|
2480
|
-
applyAccept: true,
|
|
2481
|
-
autoModify: true,
|
|
2482
|
-
delay: 0,
|
|
2483
|
-
document: global.document,
|
|
2484
|
-
keyboardMap: defaultKeyMap,
|
|
2485
|
-
pointerMap: defaultKeyMap2,
|
|
2486
|
-
skipAutoClose: false,
|
|
2487
|
-
skipClick: false,
|
|
2488
|
-
skipHover: false,
|
|
2489
|
-
skipPointerEventsCheck: false,
|
|
2490
|
-
writeToClipboard: false
|
|
2491
|
-
};
|
|
2492
|
-
var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect), {
|
|
2493
|
-
writeToClipboard: true
|
|
2494
|
-
});
|
|
2495
|
-
|
|
2496
2548
|
// src/setup/config.ts
|
|
2497
2549
|
var Config = Symbol("Config");
|
|
2498
2550
|
|
|
@@ -2520,9 +2572,6 @@ __export(api_exports, {
|
|
|
2520
2572
|
// src/convenience/click.ts
|
|
2521
2573
|
function click(element) {
|
|
2522
2574
|
return __async(this, null, function* () {
|
|
2523
|
-
if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
|
|
2524
|
-
throw new Error('unable to click element as it has or inherits pointer-events set to "none".');
|
|
2525
|
-
}
|
|
2526
2575
|
const pointerIn = [];
|
|
2527
2576
|
if (!this[Config].skipHover) {
|
|
2528
2577
|
pointerIn.push({ target: element });
|
|
@@ -2533,17 +2582,11 @@ function click(element) {
|
|
|
2533
2582
|
}
|
|
2534
2583
|
function dblClick(element) {
|
|
2535
2584
|
return __async(this, null, function* () {
|
|
2536
|
-
if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
|
|
2537
|
-
throw new Error('unable to double-click element as it has or inherits pointer-events set to "none".');
|
|
2538
|
-
}
|
|
2539
2585
|
return this.pointer([{ target: element }, "[MouseLeft][MouseLeft]"]);
|
|
2540
2586
|
});
|
|
2541
2587
|
}
|
|
2542
2588
|
function tripleClick(element) {
|
|
2543
2589
|
return __async(this, null, function* () {
|
|
2544
|
-
if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
|
|
2545
|
-
throw new Error('unable to triple-click element as it has or inherits pointer-events set to "none".');
|
|
2546
|
-
}
|
|
2547
2590
|
return this.pointer([{ target: element }, "[MouseLeft][MouseLeft][MouseLeft]"]);
|
|
2548
2591
|
});
|
|
2549
2592
|
}
|
|
@@ -2551,17 +2594,11 @@ function tripleClick(element) {
|
|
|
2551
2594
|
// src/convenience/hover.ts
|
|
2552
2595
|
function hover(element) {
|
|
2553
2596
|
return __async(this, null, function* () {
|
|
2554
|
-
if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
|
|
2555
|
-
throw new Error('unable to hover element as it has or inherits pointer-events set to "none".');
|
|
2556
|
-
}
|
|
2557
2597
|
return this.pointer({ target: element });
|
|
2558
2598
|
});
|
|
2559
2599
|
}
|
|
2560
2600
|
function unhover(element) {
|
|
2561
2601
|
return __async(this, null, function* () {
|
|
2562
|
-
if (!this[Config].skipPointerEventsCheck && !hasPointerEvents(element)) {
|
|
2563
|
-
throw new Error('unable to unhover element as it has or inherits pointer-events set to "none".');
|
|
2564
|
-
}
|
|
2565
2602
|
return this.pointer({ target: element.ownerDocument.body });
|
|
2566
2603
|
});
|
|
2567
2604
|
}
|
|
@@ -2706,7 +2743,7 @@ function selectOptionsBase(newValue, select, values) {
|
|
|
2706
2743
|
if (isElementType(select, "select")) {
|
|
2707
2744
|
if (select.multiple) {
|
|
2708
2745
|
for (const option of selectedOptions) {
|
|
2709
|
-
const withPointerEvents = this[Config].
|
|
2746
|
+
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(option);
|
|
2710
2747
|
if (withPointerEvents) {
|
|
2711
2748
|
fireEvent13.pointerOver(option);
|
|
2712
2749
|
fireEvent13.pointerEnter(select);
|
|
@@ -2728,7 +2765,7 @@ function selectOptionsBase(newValue, select, values) {
|
|
|
2728
2765
|
}
|
|
2729
2766
|
}
|
|
2730
2767
|
} else if (selectedOptions.length === 1) {
|
|
2731
|
-
const withPointerEvents = this[Config].
|
|
2768
|
+
const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
|
|
2732
2769
|
if (withPointerEvents) {
|
|
2733
2770
|
yield this.click(select);
|
|
2734
2771
|
} else {
|
|
@@ -2844,7 +2881,7 @@ function setupMain(options = {}) {
|
|
|
2844
2881
|
prepareDocument(doc);
|
|
2845
2882
|
const view = (_a = doc.defaultView) != null ? _a : window;
|
|
2846
2883
|
attachClipboardStubToView(view);
|
|
2847
|
-
return doSetup(__spreadProps(__spreadValues({}, defaultOptionsSetup), {
|
|
2884
|
+
return doSetup(__spreadProps(__spreadValues(__spreadValues({}, defaultOptionsSetup), options), {
|
|
2848
2885
|
keyboardState: createKeyboardState(),
|
|
2849
2886
|
pointerState: createPointerState(doc)
|
|
2850
2887
|
}));
|
|
@@ -2852,26 +2889,35 @@ function setupMain(options = {}) {
|
|
|
2852
2889
|
function setupDirect(options = {}, node) {
|
|
2853
2890
|
const doc = getDocument(options, node);
|
|
2854
2891
|
prepareDocument(doc);
|
|
2855
|
-
|
|
2892
|
+
const config = __spreadValues(__spreadValues({
|
|
2856
2893
|
keyboardState: createKeyboardState(),
|
|
2857
2894
|
pointerState: createPointerState(doc)
|
|
2858
|
-
}, defaultOptionsDirect), options)
|
|
2895
|
+
}, defaultOptionsDirect), options);
|
|
2896
|
+
return {
|
|
2897
|
+
config,
|
|
2898
|
+
api: doSetup(config)
|
|
2899
|
+
};
|
|
2859
2900
|
}
|
|
2860
2901
|
function setupSub(options) {
|
|
2861
2902
|
return doSetup(__spreadValues(__spreadValues({}, this[Config]), options));
|
|
2862
2903
|
}
|
|
2863
|
-
function
|
|
2904
|
+
function wrapAndBindImpl(instance, impl) {
|
|
2864
2905
|
function method(...args) {
|
|
2865
|
-
|
|
2906
|
+
setLevelRef(instance[Config], 1 /* Call */);
|
|
2907
|
+
return wrapAsync(() => impl.apply(instance, args));
|
|
2866
2908
|
}
|
|
2867
2909
|
Object.defineProperty(method, "name", { get: () => impl.name });
|
|
2868
2910
|
return method;
|
|
2869
2911
|
}
|
|
2870
|
-
var wrappedApis = Object.fromEntries(Object.entries(api_exports).map(([name, impl]) => [name, wrapImpl(impl)]));
|
|
2871
2912
|
function doSetup(config) {
|
|
2872
|
-
|
|
2873
|
-
setup: setupSub,
|
|
2913
|
+
const instance = __spreadValues({
|
|
2874
2914
|
[Config]: config
|
|
2915
|
+
}, api_exports);
|
|
2916
|
+
return __spreadProps(__spreadValues({}, Object.fromEntries(Object.entries(api_exports).map(([name, api]) => [
|
|
2917
|
+
name,
|
|
2918
|
+
wrapAndBindImpl(instance, api)
|
|
2919
|
+
]))), {
|
|
2920
|
+
setup: setupSub.bind(instance)
|
|
2875
2921
|
});
|
|
2876
2922
|
}
|
|
2877
2923
|
function getDocument(options, node) {
|
|
@@ -2900,62 +2946,60 @@ __export(directApi_exports, {
|
|
|
2900
2946
|
upload: () => upload2
|
|
2901
2947
|
});
|
|
2902
2948
|
function clear2(element) {
|
|
2903
|
-
return setupDirect().clear(element);
|
|
2949
|
+
return setupDirect().api.clear(element);
|
|
2904
2950
|
}
|
|
2905
2951
|
function click2(element, options = {}) {
|
|
2906
|
-
return setupDirect(options, element).click(element);
|
|
2952
|
+
return setupDirect(options, element).api.click(element);
|
|
2907
2953
|
}
|
|
2908
2954
|
function copy2(options = {}) {
|
|
2909
|
-
return setupDirect(options).copy();
|
|
2955
|
+
return setupDirect(options).api.copy();
|
|
2910
2956
|
}
|
|
2911
2957
|
function cut2(options = {}) {
|
|
2912
|
-
return setupDirect(options).cut();
|
|
2958
|
+
return setupDirect(options).api.cut();
|
|
2913
2959
|
}
|
|
2914
2960
|
function dblClick2(element, options = {}) {
|
|
2915
|
-
return setupDirect(options).dblClick(element);
|
|
2961
|
+
return setupDirect(options).api.dblClick(element);
|
|
2916
2962
|
}
|
|
2917
2963
|
function deselectOptions2(select, values, options = {}) {
|
|
2918
|
-
return setupDirect(options).deselectOptions(select, values);
|
|
2964
|
+
return setupDirect(options).api.deselectOptions(select, values);
|
|
2919
2965
|
}
|
|
2920
2966
|
function hover2(element, options = {}) {
|
|
2921
|
-
return setupDirect(options).hover(element);
|
|
2967
|
+
return setupDirect(options).api.hover(element);
|
|
2922
2968
|
}
|
|
2923
2969
|
function keyboard2(_0) {
|
|
2924
2970
|
return __async(this, arguments, function* (text, options = {}) {
|
|
2925
|
-
const
|
|
2926
|
-
|
|
2927
|
-
return promise.then(() => instance[Config].keyboardState);
|
|
2971
|
+
const { config, api } = setupDirect(options);
|
|
2972
|
+
return api.keyboard(text).then(() => config.keyboardState);
|
|
2928
2973
|
});
|
|
2929
2974
|
}
|
|
2930
2975
|
function pointer2(_0) {
|
|
2931
2976
|
return __async(this, arguments, function* (input, options = {}) {
|
|
2932
|
-
const
|
|
2933
|
-
|
|
2934
|
-
return promise.then(() => instance[Config].pointerState);
|
|
2977
|
+
const { config, api } = setupDirect(options);
|
|
2978
|
+
return api.pointer(input).then(() => config.pointerState);
|
|
2935
2979
|
});
|
|
2936
2980
|
}
|
|
2937
2981
|
function paste2(clipboardData, options) {
|
|
2938
|
-
return setupDirect(options).paste(clipboardData);
|
|
2982
|
+
return setupDirect(options).api.paste(clipboardData);
|
|
2939
2983
|
}
|
|
2940
2984
|
function selectOptions2(select, values, options = {}) {
|
|
2941
|
-
return setupDirect(options).selectOptions(select, values);
|
|
2985
|
+
return setupDirect(options).api.selectOptions(select, values);
|
|
2942
2986
|
}
|
|
2943
2987
|
function tripleClick2(element, options = {}) {
|
|
2944
|
-
return setupDirect(options).tripleClick(element);
|
|
2988
|
+
return setupDirect(options).api.tripleClick(element);
|
|
2945
2989
|
}
|
|
2946
2990
|
function type2(element, text, options = {}) {
|
|
2947
|
-
return setupDirect(options, element).type(element, text, options);
|
|
2991
|
+
return setupDirect(options, element).api.type(element, text, options);
|
|
2948
2992
|
}
|
|
2949
2993
|
function unhover2(element, options = {}) {
|
|
2950
|
-
const
|
|
2951
|
-
|
|
2952
|
-
return
|
|
2994
|
+
const { config, api } = setupDirect(options);
|
|
2995
|
+
config.pointerState.position.mouse.target = element;
|
|
2996
|
+
return api.unhover(element);
|
|
2953
2997
|
}
|
|
2954
2998
|
function upload2(element, fileOrFiles, options = {}) {
|
|
2955
|
-
return setupDirect(options).upload(element, fileOrFiles);
|
|
2999
|
+
return setupDirect(options).api.upload(element, fileOrFiles);
|
|
2956
3000
|
}
|
|
2957
3001
|
function tab2(options = {}) {
|
|
2958
|
-
return setupDirect().tab(options);
|
|
3002
|
+
return setupDirect().api.tab(options);
|
|
2959
3003
|
}
|
|
2960
3004
|
|
|
2961
3005
|
// src/setup/index.ts
|
|
@@ -2963,5 +3007,6 @@ var userEvent = __spreadProps(__spreadValues({}, directApi_exports), {
|
|
|
2963
3007
|
setup: setupMain
|
|
2964
3008
|
});
|
|
2965
3009
|
export {
|
|
3010
|
+
PointerEventsCheckLevel,
|
|
2966
3011
|
userEvent as default
|
|
2967
3012
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function copy(this:
|
|
1
|
+
import { Instance } from '../setup';
|
|
2
|
+
export declare function copy(this: Instance): Promise<DataTransfer | undefined>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function cut(this:
|
|
1
|
+
import { Instance } from '../setup';
|
|
2
|
+
export declare function cut(this: Instance): Promise<DataTransfer | undefined>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function paste(this:
|
|
1
|
+
import { Instance } from '../setup';
|
|
2
|
+
export declare function paste(this: Instance, clipboardData?: DataTransfer | string): Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function click(this:
|
|
3
|
-
export declare function dblClick(this:
|
|
4
|
-
export declare function tripleClick(this:
|
|
1
|
+
import { Instance } from '../setup';
|
|
2
|
+
export declare function click(this: Instance, element: Element): Promise<void>;
|
|
3
|
+
export declare function dblClick(this: Instance, element: Element): Promise<void>;
|
|
4
|
+
export declare function tripleClick(this: Instance, element: Element): Promise<void>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function hover(this:
|
|
3
|
-
export declare function unhover(this:
|
|
1
|
+
import { Instance } from '../setup';
|
|
2
|
+
export declare function hover(this: Instance, element: Element): Promise<void>;
|
|
3
|
+
export declare function unhover(this: Instance, element: Element): Promise<void>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Instance } from '../setup';
|
|
2
2
|
import { releaseAllKeys } from './keyboardAction';
|
|
3
3
|
import type { keyboardState, keyboardKey } from './types';
|
|
4
4
|
export { releaseAllKeys };
|
|
5
5
|
export type { keyboardKey, keyboardState };
|
|
6
|
-
export declare function keyboard(this:
|
|
6
|
+
export declare function keyboard(this: Instance, text: string): Promise<void>;
|
|
7
7
|
export declare function createKeyboardState(): keyboardState;
|
package/dist/types/options.d.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import type { keyboardKey } from './keyboard/types';
|
|
2
2
|
import type { pointerKey } from './pointer/types';
|
|
3
|
+
export declare enum PointerEventsCheckLevel {
|
|
4
|
+
/**
|
|
5
|
+
* Check pointer events on every user interaction that triggers a bunch of events.
|
|
6
|
+
* E.g. once for releasing a mouse button even though this triggers `pointerup`, `mouseup`, `click`, etc...
|
|
7
|
+
*/
|
|
8
|
+
EachTrigger = 4,
|
|
9
|
+
/** Check each target once per call to pointer (related) API */
|
|
10
|
+
EachApiCall = 2,
|
|
11
|
+
/** Check each event target once */
|
|
12
|
+
EachTarget = 1,
|
|
13
|
+
/** No pointer events check */
|
|
14
|
+
Never = 0
|
|
15
|
+
}
|
|
3
16
|
export interface Options {
|
|
4
17
|
/**
|
|
5
18
|
* When using `userEvent.upload`, automatically discard files
|
|
@@ -52,6 +65,16 @@ export interface Options {
|
|
|
52
65
|
* This allows to plug in different pointer devices.
|
|
53
66
|
*/
|
|
54
67
|
pointerMap?: pointerKey[];
|
|
68
|
+
/**
|
|
69
|
+
* The pointer API includes a check if an element has or inherits `pointer-events: none`.
|
|
70
|
+
* This check is known to be expensive and very expensive when checking deeply nested nodes.
|
|
71
|
+
* This option determines how often the pointer related APIs perform the check.
|
|
72
|
+
*
|
|
73
|
+
* This is a binary flag option. You can combine multiple Levels.
|
|
74
|
+
*
|
|
75
|
+
* @default PointerEventsCheckLevel.EachCall
|
|
76
|
+
*/
|
|
77
|
+
pointerEventsCheck?: PointerEventsCheckLevel | number;
|
|
55
78
|
/**
|
|
56
79
|
* `userEvent.type` automatically releases any keys still pressed at the end of the call.
|
|
57
80
|
* This option allows to opt out of this feature.
|
|
@@ -73,14 +96,6 @@ export interface Options {
|
|
|
73
96
|
* @default false
|
|
74
97
|
*/
|
|
75
98
|
skipHover?: boolean;
|
|
76
|
-
/**
|
|
77
|
-
* Calling pointer related APIs on an element triggers a check if that element can receive pointer events.
|
|
78
|
-
* This check is known to be expensive.
|
|
79
|
-
* This option allows to skip the check.
|
|
80
|
-
*
|
|
81
|
-
* @default false
|
|
82
|
-
*/
|
|
83
|
-
skipPointerEventsCheck?: boolean;
|
|
84
99
|
/**
|
|
85
100
|
* Write selected data to Clipboard API when a `cut` or `copy` is triggered.
|
|
86
101
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Instance } from '../setup';
|
|
2
2
|
import { PointerAction, PointerActionTarget } from './pointerAction';
|
|
3
3
|
import type { pointerState, pointerKey } from './types';
|
|
4
4
|
export type { pointerState, pointerKey };
|
|
@@ -6,5 +6,5 @@ declare type PointerActionInput = string | ({
|
|
|
6
6
|
keys: string;
|
|
7
7
|
} & PointerActionTarget) | PointerAction;
|
|
8
8
|
export declare type PointerInput = PointerActionInput | Array<PointerActionInput>;
|
|
9
|
-
export declare function pointer(this:
|
|
9
|
+
export declare function pointer(this: Instance, input: PointerInput): Promise<void>;
|
|
10
10
|
export declare function createPointerState(document: Document): pointerState;
|