@testing-library/dom
Advanced tools
Comparing version 9.0.1 to 9.3.0
@@ -13,3 +13,2 @@ "use strict"; | ||
*/ | ||
/** | ||
@@ -16,0 +15,0 @@ * @param {HTMLElement} element container |
@@ -13,2 +13,4 @@ "use strict"; | ||
var _allUtils = require("./all-utils"); | ||
/* eslint-disable complexity */ | ||
const queryAllByRole = (container, role, { | ||
@@ -20,2 +22,3 @@ hidden = (0, _allUtils.getConfig)().defaultHidden, | ||
selected, | ||
busy, | ||
checked, | ||
@@ -25,3 +28,9 @@ pressed, | ||
level, | ||
expanded | ||
expanded, | ||
value: { | ||
now: valueNow, | ||
min: valueMin, | ||
max: valueMax, | ||
text: valueText | ||
} = {} | ||
} = {}) => { | ||
@@ -36,6 +45,13 @@ (0, _helpers.checkContainerType)(container); | ||
} | ||
if (checked !== undefined) { | ||
if (busy !== undefined) { | ||
var _allRoles$get2; | ||
// guard against unknown roles | ||
if (((_allRoles$get2 = _ariaQuery.roles.get(role)) == null ? void 0 : _allRoles$get2.props['aria-checked']) === undefined) { | ||
if (((_allRoles$get2 = _ariaQuery.roles.get(role)) == null ? void 0 : _allRoles$get2.props['aria-busy']) === undefined) { | ||
throw new Error(`"aria-busy" is not supported on role "${role}".`); | ||
} | ||
} | ||
if (checked !== undefined) { | ||
var _allRoles$get3; | ||
// guard against unknown roles | ||
if (((_allRoles$get3 = _ariaQuery.roles.get(role)) == null ? void 0 : _allRoles$get3.props['aria-checked']) === undefined) { | ||
throw new Error(`"aria-checked" is not supported on role "${role}".`); | ||
@@ -45,5 +61,5 @@ } | ||
if (pressed !== undefined) { | ||
var _allRoles$get3; | ||
var _allRoles$get4; | ||
// guard against unknown roles | ||
if (((_allRoles$get3 = _ariaQuery.roles.get(role)) == null ? void 0 : _allRoles$get3.props['aria-pressed']) === undefined) { | ||
if (((_allRoles$get4 = _ariaQuery.roles.get(role)) == null ? void 0 : _allRoles$get4.props['aria-pressed']) === undefined) { | ||
throw new Error(`"aria-pressed" is not supported on role "${role}".`); | ||
@@ -53,3 +69,3 @@ } | ||
if (current !== undefined) { | ||
var _allRoles$get4; | ||
var _allRoles$get5; | ||
/* istanbul ignore next */ | ||
@@ -59,3 +75,3 @@ // guard against unknown roles | ||
// Leaving this for symetry and forward compatibility | ||
if (((_allRoles$get4 = _ariaQuery.roles.get(role)) == null ? void 0 : _allRoles$get4.props['aria-current']) === undefined) { | ||
if (((_allRoles$get5 = _ariaQuery.roles.get(role)) == null ? void 0 : _allRoles$get5.props['aria-current']) === undefined) { | ||
throw new Error(`"aria-current" is not supported on role "${role}".`); | ||
@@ -70,6 +86,34 @@ } | ||
} | ||
if (valueNow !== undefined) { | ||
var _allRoles$get6; | ||
// guard against unknown roles | ||
if (((_allRoles$get6 = _ariaQuery.roles.get(role)) == null ? void 0 : _allRoles$get6.props['aria-valuenow']) === undefined) { | ||
throw new Error(`"aria-valuenow" is not supported on role "${role}".`); | ||
} | ||
} | ||
if (valueMax !== undefined) { | ||
var _allRoles$get7; | ||
// guard against unknown roles | ||
if (((_allRoles$get7 = _ariaQuery.roles.get(role)) == null ? void 0 : _allRoles$get7.props['aria-valuemax']) === undefined) { | ||
throw new Error(`"aria-valuemax" is not supported on role "${role}".`); | ||
} | ||
} | ||
if (valueMin !== undefined) { | ||
var _allRoles$get8; | ||
// guard against unknown roles | ||
if (((_allRoles$get8 = _ariaQuery.roles.get(role)) == null ? void 0 : _allRoles$get8.props['aria-valuemin']) === undefined) { | ||
throw new Error(`"aria-valuemin" is not supported on role "${role}".`); | ||
} | ||
} | ||
if (valueText !== undefined) { | ||
var _allRoles$get9; | ||
// guard against unknown roles | ||
if (((_allRoles$get9 = _ariaQuery.roles.get(role)) == null ? void 0 : _allRoles$get9.props['aria-valuetext']) === undefined) { | ||
throw new Error(`"aria-valuetext" is not supported on role "${role}".`); | ||
} | ||
} | ||
if (expanded !== undefined) { | ||
var _allRoles$get5; | ||
var _allRoles$get10; | ||
// guard against unknown roles | ||
if (((_allRoles$get5 = _ariaQuery.roles.get(role)) == null ? void 0 : _allRoles$get5.props['aria-expanded']) === undefined) { | ||
if (((_allRoles$get10 = _ariaQuery.roles.get(role)) == null ? void 0 : _allRoles$get10.props['aria-expanded']) === undefined) { | ||
throw new Error(`"aria-expanded" is not supported on role "${role}".`); | ||
@@ -106,2 +150,5 @@ } | ||
} | ||
if (busy !== undefined) { | ||
return busy === (0, _roleHelpers.computeAriaBusy)(element); | ||
} | ||
if (checked !== undefined) { | ||
@@ -122,2 +169,18 @@ return checked === (0, _roleHelpers.computeAriaChecked)(element); | ||
} | ||
if (valueNow !== undefined || valueMax !== undefined || valueMin !== undefined || valueText !== undefined) { | ||
let valueMatches = true; | ||
if (valueNow !== undefined) { | ||
valueMatches && (valueMatches = valueNow === (0, _roleHelpers.computeAriaValueNow)(element)); | ||
} | ||
if (valueMax !== undefined) { | ||
valueMatches && (valueMatches = valueMax === (0, _roleHelpers.computeAriaValueMax)(element)); | ||
} | ||
if (valueMin !== undefined) { | ||
valueMatches && (valueMatches = valueMin === (0, _roleHelpers.computeAriaValueMin)(element)); | ||
} | ||
if (valueText !== undefined) { | ||
valueMatches && (valueMatches = (0, _allUtils.matches)((0, _roleHelpers.computeAriaValueText)(element) ?? null, element, valueText, text => text)); | ||
} | ||
return valueMatches; | ||
} | ||
// don't care if aria attributes are unspecified | ||
@@ -124,0 +187,0 @@ return true; |
@@ -6,2 +6,3 @@ "use strict"; | ||
}); | ||
exports.computeAriaBusy = computeAriaBusy; | ||
exports.computeAriaChecked = computeAriaChecked; | ||
@@ -12,2 +13,6 @@ exports.computeAriaCurrent = computeAriaCurrent; | ||
exports.computeAriaSelected = computeAriaSelected; | ||
exports.computeAriaValueMax = computeAriaValueMax; | ||
exports.computeAriaValueMin = computeAriaValueMin; | ||
exports.computeAriaValueNow = computeAriaValueNow; | ||
exports.computeAriaValueText = computeAriaValueText; | ||
exports.computeHeadingLevel = computeHeadingLevel; | ||
@@ -231,2 +236,11 @@ exports.getImplicitAriaRoles = getImplicitAriaRoles; | ||
* @param {Element} element - | ||
* @returns {boolean} - | ||
*/ | ||
function computeAriaBusy(element) { | ||
// https://www.w3.org/TR/wai-aria-1.1/#aria-busy | ||
return element.getAttribute('aria-busy') === 'true'; | ||
} | ||
/** | ||
* @param {Element} element - | ||
* @returns {boolean | undefined} - false/true if (not)checked, undefined if not checked-able | ||
@@ -305,2 +319,38 @@ */ | ||
return ariaLevelAttribute || implicitHeadingLevels[element.tagName]; | ||
} | ||
/** | ||
* @param {Element} element - | ||
* @returns {number | undefined} - | ||
*/ | ||
function computeAriaValueNow(element) { | ||
const valueNow = element.getAttribute('aria-valuenow'); | ||
return valueNow === null ? undefined : +valueNow; | ||
} | ||
/** | ||
* @param {Element} element - | ||
* @returns {number | undefined} - | ||
*/ | ||
function computeAriaValueMax(element) { | ||
const valueMax = element.getAttribute('aria-valuemax'); | ||
return valueMax === null ? undefined : +valueMax; | ||
} | ||
/** | ||
* @param {Element} element - | ||
* @returns {number | undefined} - | ||
*/ | ||
function computeAriaValueMin(element) { | ||
const valueMin = element.getAttribute('aria-valuemin'); | ||
return valueMin === null ? undefined : +valueMin; | ||
} | ||
/** | ||
* @param {Element} element - | ||
* @returns {string | undefined} - | ||
*/ | ||
function computeAriaValueText(element) { | ||
const valueText = element.getAttribute('aria-valuetext'); | ||
return valueText === null ? undefined : valueText; | ||
} |
@@ -57,8 +57,14 @@ "use strict"; | ||
} | ||
// we *could* (maybe should?) use `advanceTimersToNextTimer` but it's | ||
// possible that could make this loop go on forever if someone is using | ||
// third party code that's setting up recursive timers so rapidly that | ||
// the user's timer's don't get a chance to resolve. So we'll advance | ||
// by an interval instead. (We have a test for this case). | ||
advanceTimersWrapper(() => { | ||
// In this rare case, we *need* to wait for in-flight promises | ||
// to resolve before continuing. We don't need to take advantage | ||
// of parallelization so we're fine. | ||
// https://stackoverflow.com/a/59243586/971592 | ||
// eslint-disable-next-line no-await-in-loop | ||
await advanceTimersWrapper(async () => { | ||
// we *could* (maybe should?) use `advanceTimersToNextTimer` but it's | ||
// possible that could make this loop go on forever if someone is using | ||
// third party code that's setting up recursive timers so rapidly that | ||
// the user's timer's don't get a chance to resolve. So we'll advance | ||
// by an interval instead. (We have a test for this case). | ||
jest.advanceTimersByTime(interval); | ||
@@ -75,14 +81,2 @@ }); | ||
} | ||
// In this rare case, we *need* to wait for in-flight promises | ||
// to resolve before continuing. We don't need to take advantage | ||
// of parallelization so we're fine. | ||
// https://stackoverflow.com/a/59243586/971592 | ||
// eslint-disable-next-line no-await-in-loop | ||
await advanceTimersWrapper(async () => { | ||
await new Promise(r => { | ||
setTimeout(r, 0); | ||
jest.advanceTimersByTime(0); | ||
}); | ||
}); | ||
} | ||
@@ -89,0 +83,0 @@ } else { |
{ | ||
"name": "@testing-library/dom", | ||
"version": "9.0.1", | ||
"version": "9.3.0", | ||
"description": "Simple and complete DOM testing utilities that encourage good testing practices.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -85,2 +85,7 @@ import {ByRoleMatcher, Matcher, MatcherOptions} from './matches' | ||
* If true only includes elements in the query set that are marked as | ||
* busy in the accessibility tree, i.e., `aria-busy="true"` | ||
*/ | ||
busy?: boolean | ||
/** | ||
* If true only includes elements in the query set that are marked as | ||
* checked in the accessibility tree, i.e., `aria-checked="true"` | ||
@@ -109,2 +114,8 @@ */ | ||
level?: number | ||
value?: { | ||
now?: number | ||
min?: number | ||
max?: number | ||
text?: Matcher | ||
} | ||
/** | ||
@@ -111,0 +122,0 @@ * Includes every role used in the `role` attribute |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2953866
25466