@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.
@@ -12,7 +12,9 @@
12
12
  "Bash(grep:*)",
13
13
  "Bash(touch:*)",
14
14
  "Bash(git stash:*)",
15
- "Bash(npm publish:*)"
15
+ "Bash(npm publish:*)",
16
+ "Bash(git commit:*)",
17
+ "Bash(git push:*)"
16
18
  ]
17
19
  },
18
20
  "enableAllProjectMcpServers": false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afixt/test-utils",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Various utilities for accessibility testing",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
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} name - The name of the attribute to look for.
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) {
@@ -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) return false;
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,
@@ -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) return "";
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 getAriaAttributes = (element) => {
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 = getAriaAttributes;
19
+ module.exports = getAriaAttributesByElement;
@@ -1,5 +1,5 @@
1
1
  /**
2
- *
2
+ * Gets all focusable elements within the specified container element.
3
3
  * @param {Element} el - the element to be tested
4
4
  * @returns {Array} - Array of focusable elements
5
5
  */
package/src/isVisible.js CHANGED
@@ -5,7 +5,15 @@
5
5
  * @returns {boolean}
6
6
  */
7
7
  function isVisible(element, strict = false) {
8
- if (!element) return false;
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;
@@ -72,7 +72,7 @@ const stringUtils = (function () {
72
72
  * @returns {boolean}
73
73
  */
74
74
  function isAlphaNumeric(str) {
75
- const pattern = "/^[a-zA-Z0-9]+$/";
75
+ const pattern = /^[a-zA-Z0-9]+$/;
76
76
  return pattern.test(str);
77
77
  }
78
78