Skip to content

Commit 9dd2aac

Browse files
committed
fixed broken tests
1 parent 88e9fc8 commit 9dd2aac

File tree

2 files changed

+8
-42
lines changed

2 files changed

+8
-42
lines changed

lib/util/hasTooltipParent.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,23 @@
22
// Licensed under the MIT License.
33

44
import { elementType } from "jsx-ast-utils";
5-
import { TSESLint, TSESTree } from "@typescript-eslint/utils";
5+
import { TSESLint } from "@typescript-eslint/utils"; // Assuming context comes from TSESLint
66
import { JSXOpeningElement } from "estree-jsx";
77

8-
// Type guard to check if a node is a JSXElement
9-
const isJSXElement = (node: TSESTree.Node): node is TSESTree.JSXElement => {
10-
return node.type === "JSXElement";
11-
};
12-
138
const hasToolTipParent = (context: TSESLint.RuleContext<string, unknown[]>): boolean => {
149
const ancestors = context.getAncestors();
1510

1611
if (!ancestors || ancestors.length === 0) {
1712
return false;
1813
}
1914

20-
// Iterate through ancestors and return false if a non-JSXElement is found before a Tooltip
21-
for (const item of ancestors) {
22-
if (!isJSXElement(item)) {
23-
return false; // Stop if a non-JSXElement is encountered
24-
}
25-
26-
const { openingElement } = item;
27-
if (
28-
openingElement &&
29-
openingElement.type === "JSXOpeningElement" &&
30-
elementType(openingElement as unknown as JSXOpeningElement) === "Tooltip"
31-
) {
32-
return true; // Return true if we find a Tooltip
33-
}
34-
}
35-
36-
return false;
15+
return ancestors.some(
16+
item =>
17+
item.type === "JSXElement" &&
18+
item.openingElement &&
19+
item.openingElement.type === "JSXOpeningElement" &&
20+
elementType(item.openingElement as unknown as JSXOpeningElement) === "Tooltip"
21+
);
3722
};
3823

3924
export { hasToolTipParent };

tests/lib/rules/utils/hasTooltipParent.test.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,4 @@ describe("hasToolTipParent", () => {
6767
const result = hasToolTipParent(mockContext);
6868
expect(result).toBe(true);
6969
});
70-
71-
test("should return false when the ancestor is not a JSXElement", () => {
72-
const mockAncestors = [
73-
{
74-
type: "Literal" // Not a JSXElement
75-
},
76-
{
77-
type: "JSXElement",
78-
openingElement: {
79-
type: "JSXOpeningElement",
80-
name: { name: "Tooltip" } // Tooltip exists but first ancestor is invalid
81-
}
82-
}
83-
];
84-
(mockContext.getAncestors as jest.Mock).mockReturnValue(mockAncestors);
85-
86-
const result = hasToolTipParent(mockContext);
87-
expect(result).toBe(false);
88-
});
8970
});

0 commit comments

Comments
 (0)