@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 +1 -1
- package/src/domUtils.js +1 -1
- package/src/getAriaAttributesByElement.js +2 -2
- package/src/getFocusableElements.js +1 -1
- package/src/stringUtils.js +1 -1
- package/todo.md +0 -1
- package/repairs-needed.md +0 -84
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) {
|
|
@@ -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/stringUtils.js
CHANGED
package/todo.md
CHANGED
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
|