Skip to content
TypeScript

test(web): ChatMarkdown thread find waits for highlights to settle (#21121)

Julius Marminged0918f1659f4
diff --git a/apps/web/src/components/ChatMarkdown.browser.test.tsx b/apps/web/src/components/ChatMarkdown.browser.test.tsx
index 942259fd5de..eac41c7eb0b 100644
--- a/apps/web/src/components/ChatMarkdown.browser.test.tsx
+++ b/apps/web/src/components/ChatMarkdown.browser.test.tsx
@@ -830,10 +830,14 @@ describe("ChatMarkdown thread find", () => {
),
);
await frame();
- const ranges = [...CSS.highlights.values()].flatMap((value) => [...value]);
- expect(ranges.map((range) => (range as Range).toString())).toEqual(
- Array.from({ length: count }, () => query),
- );
+ // Lazy blocks such as Mermaid can swap their source text after the first frame,
+ // emptying a range for a moment, so wait for the highlights to settle.
+ await vi.waitFor(() => {
+ const ranges = [...CSS.highlights.values()].flatMap((value) => [...value]);
+ expect(ranges.map((range) => (range as Range).toString())).toEqual(
+ Array.from({ length: count }, () => query),
+ );
+ });
const segments =
searchableMessageSegments(
{ role: user ? "user" : "assistant", text, streaming: false },