Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
test(client): unmount editor and remove container after each Code spec
drakeo33855457e6a1fa9
diff --git a/apps/client/src/widgets/type_widgets/code/Code.spec.tsx b/apps/client/src/widgets/type_widgets/code/Code.spec.tsxindex 11aa1c3aae..be9c724334 100644--- a/apps/client/src/widgets/type_widgets/code/Code.spec.tsx+++ b/apps/client/src/widgets/type_widgets/code/Code.spec.tsx@@ -1,7 +1,7 @@// @vitest-environment jsdomimport { render } from "preact";import { act } from "preact/test-utils";-import { describe, expect, it, vi } from "vitest";+import { afterEach, describe, expect, it, vi } from "vitest";import { ParentComponent } from "../../react/react_utils";import { EditableCode } from "./Code";@@ -19,19 +19,30 @@ function fakeNote(noteId: string, content: string) {}describe("EditableCode", () => {+ let container: HTMLElement | undefined;++ afterEach(() => {+ if (container) {+ act(() => { render(null, container as HTMLElement); });+ container.remove();+ container = undefined;+ }+ });+// A preview-only Markdown note keeps its (hidden) editor mounted and relies on this callback to// feed the preview, so it has to fire when a different note's content is loaded.it("reports the content of the new note after a note switch", async () => {const onContentChanged = vi.fn();const parent = { registerHandler() {}, removeHandler() {}, componentId: "c" } as any;- const container = document.createElement("div");- document.body.appendChild(container);+ const mountPoint = document.createElement("div");+ document.body.appendChild(mountPoint);+ container = mountPoint;const show = (note: any) => render(<ParentComponent.Provider value={parent}><EditableCode note={note} ntxId="ntx" parentComponent={parent} noteContext={undefined} viewScope={undefined} onContentChanged={onContentChanged} /></ParentComponent.Provider>,- container+ mountPoint);await act(async () => { show(fakeNote("a", "# Note A")); });