@afixt/test-utils 1.1.0 → 1.1.1

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.1",
4
4
  "description": "Various utilities for accessibility testing",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -0,0 +1,84 @@
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
@@ -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
 
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;
package/todo.md CHANGED
@@ -1 +1,2 @@
1
1
  # Test-Utils Todo
2
+