@testing-library/user-event 14.1.1 → 14.2.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/dist/index.cjs CHANGED
@@ -917,7 +917,7 @@ function moveSelection(node, direction) {
917
917
  });
918
918
  } else {
919
919
  const selection = node.ownerDocument.getSelection();
920
- if (!selection) {
920
+ if (!(selection == null ? void 0 : selection.focusNode)) {
921
921
  return;
922
922
  }
923
923
  if (selection.isCollapsed) {
@@ -1317,14 +1317,19 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
1317
1317
 
1318
1318
  // src/utils/pointer/cssPointerEvents.ts
1319
1319
  function hasPointerEvents(element) {
1320
+ var _a;
1321
+ return ((_a = closestPointerEventsDeclaration(element)) == null ? void 0 : _a.pointerEvents) !== "none";
1322
+ }
1323
+ function closestPointerEventsDeclaration(element) {
1320
1324
  const window = getWindow(element);
1321
- for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
1325
+ for (let el = element, tree = []; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
1326
+ tree.push(el);
1322
1327
  const pointerEvents = window.getComputedStyle(el).pointerEvents;
1323
1328
  if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
1324
- return pointerEvents !== "none";
1329
+ return { pointerEvents, tree };
1325
1330
  }
1326
1331
  }
1327
- return true;
1332
+ return void 0;
1328
1333
  }
1329
1334
  var PointerEventsCheck = Symbol("Last check for pointer-events");
1330
1335
  function assertPointerEvents(config, element) {
@@ -1333,15 +1338,59 @@ function assertPointerEvents(config, element) {
1333
1338
  if (!needsCheck) {
1334
1339
  return;
1335
1340
  }
1336
- const result = hasPointerEvents(element);
1341
+ const declaration = closestPointerEventsDeclaration(element);
1337
1342
  element[PointerEventsCheck] = {
1338
1343
  [1 /* Call */]: getLevelRef(config, 1 /* Call */),
1339
1344
  [2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
1340
- result
1345
+ result: (declaration == null ? void 0 : declaration.pointerEvents) !== "none"
1341
1346
  };
1342
- if (!result) {
1343
- throw new Error('Unable to perform pointer interaction as the element has or inherits pointer-events set to "none".');
1347
+ if ((declaration == null ? void 0 : declaration.pointerEvents) === "none") {
1348
+ throw new Error([
1349
+ `Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? "inherits" : "has"} \`pointer-events: none\`:`,
1350
+ "",
1351
+ printTree(declaration.tree)
1352
+ ].join("\n"));
1353
+ }
1354
+ }
1355
+ function printTree(tree) {
1356
+ return tree.reverse().map((el, i) => [
1357
+ "".padEnd(i),
1358
+ el.tagName,
1359
+ el.id && `#${el.id}`,
1360
+ el.hasAttribute("data-testid") && `(testId=${el.getAttribute("data-testid")})`,
1361
+ getLabelDescr(el),
1362
+ tree.length > 1 && i === 0 && " <-- This element declared `pointer-events: none`",
1363
+ tree.length > 1 && i === tree.length - 1 && " <-- Asserted pointer events here"
1364
+ ].filter(Boolean).join("")).join("\n");
1365
+ }
1366
+ function getLabelDescr(element) {
1367
+ var _a, _b, _c, _d;
1368
+ let label;
1369
+ if (element.hasAttribute("aria-label")) {
1370
+ label = element.getAttribute("aria-label");
1371
+ } else if (element.hasAttribute("aria-labelledby")) {
1372
+ label = (_b = (_a = element.ownerDocument.getElementById(element.getAttribute("aria-labelledby"))) == null ? void 0 : _a.textContent) == null ? void 0 : _b.trim();
1373
+ } else if (isElementType(element, [
1374
+ "button",
1375
+ "input",
1376
+ "meter",
1377
+ "output",
1378
+ "progress",
1379
+ "select",
1380
+ "textarea"
1381
+ ]) && ((_c = element.labels) == null ? void 0 : _c.length)) {
1382
+ label = Array.from(element.labels).map((el) => {
1383
+ var _a2;
1384
+ return (_a2 = el.textContent) == null ? void 0 : _a2.trim();
1385
+ }).join("|");
1386
+ } else if (isElementType(element, "button")) {
1387
+ label = (_d = element.textContent) == null ? void 0 : _d.trim();
1388
+ }
1389
+ label = label == null ? void 0 : label.replace(/\n/g, " ");
1390
+ if (Number(label == null ? void 0 : label.length) > 30) {
1391
+ label = `${label == null ? void 0 : label.substring(0, 29)}\u2026`;
1344
1392
  }
1393
+ return label ? `(label=${label})` : "";
1345
1394
  }
1346
1395
  function hasBitFlag(conf, flag) {
1347
1396
  return (conf & flag) > 0;
@@ -2713,6 +2762,7 @@ async function selectOptionsBase(newValue, select, values) {
2713
2762
  if (withPointerEvents) {
2714
2763
  this.dispatchUIEvent(option, "click");
2715
2764
  }
2765
+ await wait(this[Config]);
2716
2766
  }
2717
2767
  } else if (selectedOptions.length === 1) {
2718
2768
  const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
@@ -2731,6 +2781,7 @@ async function selectOptionsBase(newValue, select, values) {
2731
2781
  this.dispatchUIEvent(select, "mouseup");
2732
2782
  this.dispatchUIEvent(select, "click");
2733
2783
  }
2784
+ await wait(this[Config]);
2734
2785
  } else {
2735
2786
  throw (0, import_dom4.getConfig)().getElementError(`Cannot select multiple options on a non-multiple select`, select);
2736
2787
  }
@@ -2846,7 +2897,10 @@ function setupSub(options) {
2846
2897
  function wrapAndBindImpl(instance, impl) {
2847
2898
  function method(...args) {
2848
2899
  setLevelRef(instance[Config], 1 /* Call */);
2849
- return wrapAsync(() => impl.apply(instance, args));
2900
+ return wrapAsync(() => impl.apply(instance, args).then(async (ret) => {
2901
+ await wait(instance[Config]);
2902
+ return ret;
2903
+ }));
2850
2904
  }
2851
2905
  Object.defineProperty(method, "name", { get: () => impl.name });
2852
2906
  return method;
package/dist/index.mjs CHANGED
@@ -933,7 +933,7 @@ function moveSelection(node, direction) {
933
933
  });
934
934
  } else {
935
935
  const selection = node.ownerDocument.getSelection();
936
- if (!selection) {
936
+ if (!(selection == null ? void 0 : selection.focusNode)) {
937
937
  return;
938
938
  }
939
939
  if (selection.isCollapsed) {
@@ -1333,14 +1333,19 @@ var defaultOptionsSetup = __spreadProps(__spreadValues({}, defaultOptionsDirect)
1333
1333
 
1334
1334
  // src/utils/pointer/cssPointerEvents.ts
1335
1335
  function hasPointerEvents(element) {
1336
+ var _a;
1337
+ return ((_a = closestPointerEventsDeclaration(element)) == null ? void 0 : _a.pointerEvents) !== "none";
1338
+ }
1339
+ function closestPointerEventsDeclaration(element) {
1336
1340
  const window = getWindow(element);
1337
- for (let el = element; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
1341
+ for (let el = element, tree = []; el == null ? void 0 : el.ownerDocument; el = el.parentElement) {
1342
+ tree.push(el);
1338
1343
  const pointerEvents = window.getComputedStyle(el).pointerEvents;
1339
1344
  if (pointerEvents && !["inherit", "unset"].includes(pointerEvents)) {
1340
- return pointerEvents !== "none";
1345
+ return { pointerEvents, tree };
1341
1346
  }
1342
1347
  }
1343
- return true;
1348
+ return void 0;
1344
1349
  }
1345
1350
  var PointerEventsCheck = Symbol("Last check for pointer-events");
1346
1351
  function assertPointerEvents(config, element) {
@@ -1349,15 +1354,59 @@ function assertPointerEvents(config, element) {
1349
1354
  if (!needsCheck) {
1350
1355
  return;
1351
1356
  }
1352
- const result = hasPointerEvents(element);
1357
+ const declaration = closestPointerEventsDeclaration(element);
1353
1358
  element[PointerEventsCheck] = {
1354
1359
  [1 /* Call */]: getLevelRef(config, 1 /* Call */),
1355
1360
  [2 /* Trigger */]: getLevelRef(config, 2 /* Trigger */),
1356
- result
1361
+ result: (declaration == null ? void 0 : declaration.pointerEvents) !== "none"
1357
1362
  };
1358
- if (!result) {
1359
- throw new Error('Unable to perform pointer interaction as the element has or inherits pointer-events set to "none".');
1360
- }
1363
+ if ((declaration == null ? void 0 : declaration.pointerEvents) === "none") {
1364
+ throw new Error([
1365
+ `Unable to perform pointer interaction as the element ${declaration.tree.length > 1 ? "inherits" : "has"} \`pointer-events: none\`:`,
1366
+ "",
1367
+ printTree(declaration.tree)
1368
+ ].join("\n"));
1369
+ }
1370
+ }
1371
+ function printTree(tree) {
1372
+ return tree.reverse().map((el, i) => [
1373
+ "".padEnd(i),
1374
+ el.tagName,
1375
+ el.id && `#${el.id}`,
1376
+ el.hasAttribute("data-testid") && `(testId=${el.getAttribute("data-testid")})`,
1377
+ getLabelDescr(el),
1378
+ tree.length > 1 && i === 0 && " <-- This element declared `pointer-events: none`",
1379
+ tree.length > 1 && i === tree.length - 1 && " <-- Asserted pointer events here"
1380
+ ].filter(Boolean).join("")).join("\n");
1381
+ }
1382
+ function getLabelDescr(element) {
1383
+ var _a, _b, _c, _d;
1384
+ let label;
1385
+ if (element.hasAttribute("aria-label")) {
1386
+ label = element.getAttribute("aria-label");
1387
+ } else if (element.hasAttribute("aria-labelledby")) {
1388
+ label = (_b = (_a = element.ownerDocument.getElementById(element.getAttribute("aria-labelledby"))) == null ? void 0 : _a.textContent) == null ? void 0 : _b.trim();
1389
+ } else if (isElementType(element, [
1390
+ "button",
1391
+ "input",
1392
+ "meter",
1393
+ "output",
1394
+ "progress",
1395
+ "select",
1396
+ "textarea"
1397
+ ]) && ((_c = element.labels) == null ? void 0 : _c.length)) {
1398
+ label = Array.from(element.labels).map((el) => {
1399
+ var _a2;
1400
+ return (_a2 = el.textContent) == null ? void 0 : _a2.trim();
1401
+ }).join("|");
1402
+ } else if (isElementType(element, "button")) {
1403
+ label = (_d = element.textContent) == null ? void 0 : _d.trim();
1404
+ }
1405
+ label = label == null ? void 0 : label.replace(/\n/g, " ");
1406
+ if (Number(label == null ? void 0 : label.length) > 30) {
1407
+ label = `${label == null ? void 0 : label.substring(0, 29)}\u2026`;
1408
+ }
1409
+ return label ? `(label=${label})` : "";
1361
1410
  }
1362
1411
  function hasBitFlag(conf, flag) {
1363
1412
  return (conf & flag) > 0;
@@ -2776,6 +2825,7 @@ function selectOptionsBase(newValue, select, values) {
2776
2825
  if (withPointerEvents) {
2777
2826
  this.dispatchUIEvent(option, "click");
2778
2827
  }
2828
+ yield wait(this[Config]);
2779
2829
  }
2780
2830
  } else if (selectedOptions.length === 1) {
2781
2831
  const withPointerEvents = this[Config].pointerEventsCheck === 0 ? true : hasPointerEvents(select);
@@ -2794,6 +2844,7 @@ function selectOptionsBase(newValue, select, values) {
2794
2844
  this.dispatchUIEvent(select, "mouseup");
2795
2845
  this.dispatchUIEvent(select, "click");
2796
2846
  }
2847
+ yield wait(this[Config]);
2797
2848
  } else {
2798
2849
  throw getConfig3().getElementError(`Cannot select multiple options on a non-multiple select`, select);
2799
2850
  }
@@ -2914,7 +2965,10 @@ function setupSub(options) {
2914
2965
  function wrapAndBindImpl(instance, impl) {
2915
2966
  function method(...args) {
2916
2967
  setLevelRef(instance[Config], 1 /* Call */);
2917
- return wrapAsync(() => impl.apply(instance, args));
2968
+ return wrapAsync(() => impl.apply(instance, args).then((ret) => __async(this, null, function* () {
2969
+ yield wait(instance[Config]);
2970
+ return ret;
2971
+ })));
2918
2972
  }
2919
2973
  Object.defineProperty(method, "name", { get: () => impl.name });
2920
2974
  return method;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testing-library/user-event",
3
- "version": "14.1.1",
3
+ "version": "14.2.0",
4
4
  "description": "Fire events the same way the user does",
5
5
  "keywords": [
6
6
  "react-testing-library",