@afixt/test-utils 1.1.1 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afixt/test-utils",
3
- "version": "1.1.1",
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) {
@@ -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
  */
@@ -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
 
package/todo.md CHANGED
@@ -1,2 +1 @@
1
1
  # Test-Utils Todo
2
-
package/repairs-needed.md DELETED
@@ -1,84 +0,0 @@
1
- # Required Changes for @afixt/test-utils Library
2
-
3
- ## Issue
4
-
5
- The browser extension is throwing "Invalid input: element must be a DOM Element,
6
- got: null" errors when viewing dynamic sites like CNN.com. The error originates
7
- from the @afixt/test-utils library functions.
8
-
9
- ## Root Cause
10
-
11
- The `isVisible()` function (and potentially other functions) in
12
- @afixt/test-utils throws an error when passed null or non-Element arguments.
13
- This happens frequently during DOM mutations when:
14
-
15
- 1. Elements are removed from the DOM during repair operations
16
- 2. Mutation observers fire on disconnected elements
17
- 3. Elements become stale between detection and processing
18
-
19
- ## Required Changes
20
-
21
- ### 1. isVisible() Function
22
-
23
- The function needs to handle null/invalid inputs gracefully:
24
-
25
- ```javascript
26
- function isVisible(element, strict = false) {
27
- // Add null check at the beginning
28
- if (!element || !(element instanceof Element)) {
29
- return false;
30
- }
31
-
32
- // Check if element is still connected to the DOM
33
- if (!element.isConnected) {
34
- return false;
35
- }
36
-
37
- // ... rest of the existing function
38
- }
39
- ```
40
-
41
- ### 2. getAccessibleText() Function
42
-
43
- Should handle null elements:
44
-
45
- ```javascript
46
- function getAccessibleText(element) {
47
- if (!element || !(element instanceof Element)) {
48
- return '';
49
- }
50
-
51
- if (!element.isConnected) {
52
- return '';
53
- }
54
-
55
- // ... rest of the existing function
56
- }
57
- ```
58
-
59
- ### 3. getAccessibleName() Function
60
-
61
- Should handle null elements:
62
-
63
- ```javascript
64
- function getAccessibleName(element) {
65
- if (!element || !(element instanceof Element)) {
66
- return '';
67
- }
68
-
69
- if (!element.isConnected) {
70
- return '';
71
- }
72
-
73
- // ... rest of the existing function
74
- }
75
- ```
76
-
77
- ## Why These Changes Are Needed
78
-
79
- 1. **Defensive Programming**: DOM elements can become null or disconnected at
80
- any time, especially in dynamic web applications
81
- 2. **Mutation Observer Behavior**: When observing DOM changes, elements can be
82
- removed between the time a mutation is detected and when it's processed
83
- 3. **Library Robustness**: A utility library should handle invalid inputs
84
- gracefully rather than throwing errors