Skip to content

Commit aa57bae

Browse files
authored
test: enhance link filtering logic in IssueList tests for better URL validation (#379)
Signed-off-by: Daniel Ntege <danientege785@gmail.com>
1 parent 64fce00 commit aa57bae

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/components/IssueList/__tests__/IssueList.test.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,20 @@ describe("IssueList", () => {
7979
expect(screen.queryByText("Assigned issue")).not.toBeInTheDocument();
8080
expect(screen.queryByText("Closed issue")).not.toBeInTheDocument();
8181

82-
const issueLinks = screen
83-
.getAllByRole("link")
84-
.filter(link =>
85-
link.getAttribute("href")?.startsWith("https://issues.example"),
86-
);
82+
const issueLinks = screen.getAllByRole("link").filter(link => {
83+
const href = link.getAttribute("href");
84+
85+
if (!href) {
86+
return false;
87+
}
88+
89+
try {
90+
const url = new URL(href);
91+
return url.protocol === "https:" && url.hostname === "issues.example";
92+
} catch {
93+
return false;
94+
}
95+
});
8796

8897
expect(issueLinks.map(link => link.textContent)).toEqual([
8998
"Go issue",

0 commit comments

Comments
 (0)