Skip to content

Commit 9bc7412

Browse files
committed
test(web): await long-link DOM assertions
1 parent 20c1fd6 commit 9bc7412

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

‎apps/web/src/components/chat/MarkdownExternalLink.browser.test.tsx‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, it } from "vite-plus/test";
1+
import { expect, it, vi } from "vite-plus/test";
22

33
import { render } from "../../../test/render";
44
import "../../index.css";
@@ -38,12 +38,17 @@ it.each(["plain", "formatted"] as const)(
3838

3939
const longUrl = url(16_000);
4040
await screen.rerender(link(longUrl));
41-
const anchor = screen.container.querySelector("a")!;
42-
const table = screen.container.querySelector("table")!;
43-
expect(anchor.getAttribute("href")).toBe(longUrl);
44-
expect(anchor.textContent).toBe(longUrl + (kind === "formatted" ? " details" : ""));
45-
expect(anchor.querySelectorAll("*")).toHaveLength(initialElementCount);
46-
if (kind === "formatted") expect(anchor.querySelector("strong")?.textContent).toBe(" details");
47-
expect(table.scrollWidth).toBeLessThanOrEqual(screen.container.firstElementChild!.clientWidth);
41+
await vi.waitFor(() => {
42+
const anchor = screen.container.querySelector("a")!;
43+
const table = screen.container.querySelector("table")!;
44+
expect(anchor.getAttribute("href")).toBe(longUrl);
45+
expect(anchor.textContent).toBe(longUrl + (kind === "formatted" ? " details" : ""));
46+
expect(anchor.querySelectorAll("*")).toHaveLength(initialElementCount);
47+
if (kind === "formatted")
48+
expect(anchor.querySelector("strong")?.textContent).toBe(" details");
49+
expect(table.scrollWidth).toBeLessThanOrEqual(
50+
screen.container.firstElementChild!.clientWidth,
51+
);
52+
});
4853
},
4954
);

0 commit comments

Comments
 (0)