@afixt/test-utils 1.1.0 → 1.1.2
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/.claude/settings.local.json +3 -1
- package/package.json +1 -1
- package/src/domUtils.js +1 -1
- package/src/getAccessibleName.js +7 -1
- package/src/getAccessibleText.js +7 -1
- package/src/getAriaAttributesByElement.js +2 -2
- package/src/getFocusableElements.js +1 -1
- package/src/isVisible.js +9 -1
- package/src/stringUtils.js +1 -1
package/package.json
CHANGED
package/src/domUtils.js
CHANGED
|
@@ -3,7 +3,7 @@ const domUtils = {
|
|
|
3
3
|
* Checks if the specified element has the given attribute.
|
|
4
4
|
*
|
|
5
5
|
* @param {HTMLElement} element - The DOM element to check.
|
|
6
|
-
* @param {string}
|
|
6
|
+
* @param {string} attrName - The name of the attribute to look for.
|
|
7
7
|
* @returns {boolean} True if the element has the attribute, false otherwise.
|
|
8
8
|
*/
|
|
9
9
|
hasAttr(element, attrName) {
|
package/src/getAccessibleName.js
CHANGED
|
@@ -7,7 +7,13 @@ const { getAccessibleText } = require("./getAccessibleText.js");
|
|
|
7
7
|
* @returns {string|boolean} The accessible name or false if none exists
|
|
8
8
|
*/
|
|
9
9
|
function getAccessibleName(element) {
|
|
10
|
-
if (!element)
|
|
10
|
+
if (!element || !(element instanceof Element)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!element.isConnected) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
11
17
|
|
|
12
18
|
// These are elements which are totally not able to be labeled at all.
|
|
13
19
|
// Even if the title attribute is valid per HTML for these elements,
|
package/src/getAccessibleText.js
CHANGED
|
@@ -6,7 +6,13 @@ const { isEmpty } = require("./stringUtils.js");
|
|
|
6
6
|
* @returns {string} The accessible text.
|
|
7
7
|
*/
|
|
8
8
|
function getAccessibleText(el) {
|
|
9
|
-
if (!el)
|
|
9
|
+
if (!el || !(el instanceof Element)) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (!el.isConnected) {
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
10
16
|
|
|
11
17
|
let textContent = "";
|
|
12
18
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param {Element} element - The DOM element from which to extract ARIA attributes.
|
|
5
5
|
* @returns {string[]} An array of ARIA attribute names present on the element.
|
|
6
6
|
*/
|
|
7
|
-
const
|
|
7
|
+
const getAriaAttributesByElement = (element) => {
|
|
8
8
|
let result = [];
|
|
9
9
|
const attrs = element.attributes;
|
|
10
10
|
|
|
@@ -16,4 +16,4 @@ const getAriaAttributes = (element) => {
|
|
|
16
16
|
return result;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
module.exports =
|
|
19
|
+
module.exports = getAriaAttributesByElement;
|
package/src/isVisible.js
CHANGED
|
@@ -5,7 +5,15 @@
|
|
|
5
5
|
* @returns {boolean}
|
|
6
6
|
*/
|
|
7
7
|
function isVisible(element, strict = false) {
|
|
8
|
-
|
|
8
|
+
// Add null check at the beginning
|
|
9
|
+
if (!element || !(element instanceof Element)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Check if element is still connected to the DOM
|
|
14
|
+
if (!element.isConnected) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
9
17
|
|
|
10
18
|
const id = element.id;
|
|
11
19
|
let visible = true;
|