Skip to content
TypeScript

test(web): file editor dismissal test waits for the editor to render (#30350)

Julius Marmingefcad9de8cee5
diff --git a/apps/web/src/components/files/fileEditorDismissal.browser.test.tsx b/apps/web/src/components/files/fileEditorDismissal.browser.test.tsx
index 7f7d6601c68..efc7d0fcc82 100644
--- a/apps/web/src/components/files/fileEditorDismissal.browser.test.tsx
+++ b/apps/web/src/components/files/fileEditorDismissal.browser.test.tsx
@@ -1,3 +1,4 @@
+import { DEFAULT_THEMES, preloadHighlighter } from "@pierre/diffs";
import { Editor, type EditorFactory } from "@pierre/diffs/edit";
import { EditProvider, File } from "@pierre/diffs/react";
import { describe, expect, it, vi } from "vite-plus/test";
@@ -12,6 +13,8 @@ describe("installFileEditorDismissal", () => {
let editor: Editor<"file" | "file-diff", undefined, undefined> | undefined;
const createEditor: EditorFactory<undefined, undefined> = (...args) =>
(editor = new Editor(...args));
+ // File paints nothing until the shared highlighter has loaded; once it has, mount renders synchronously.
+ await preloadHighlighter({ themes: Object.values(DEFAULT_THEMES), langs: ["typescript"] });
await using screen = await render(
<>
<p>Assistant reply</p>
@@ -23,17 +26,14 @@ describe("installFileEditorDismissal", () => {
</>,
);
const shadowRoot = () => screen.container.querySelector("diffs-container")?.shadowRoot;
- const content = await vi.waitFor(() => {
- const element = shadowRoot()?.querySelector<HTMLElement>("[data-content]");
- expect(element).toBeTruthy();
- return element!;
- });
+ const content = shadowRoot()?.querySelector<HTMLElement>("[data-content]");
+ expect(content).toBeTruthy();
editor!.setSelections([
{ start: { line: 0, character: 8 }, end: { line: 0, character: 8 }, direction: "none" },
]);
const isMac = isMacPlatform(navigator.platform);
- content.dispatchEvent(
+ content!.dispatchEvent(
new KeyboardEvent("keydown", {
key: "f",
code: "KeyF",