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): stop the note info spec leaking an unhandled rejection
Elian Doran6bbf4e4bf6c3
diff --git a/apps/client/src/test/setup.ts b/apps/client/src/test/setup.tsindex 37a351e91f..2f654a870e 100644--- a/apps/client/src/test/setup.ts+++ b/apps/client/src/test/setup.ts@@ -1,12 +1,11 @@import $ from "jquery";-import { beforeAll, vi } from "vitest";+import { vi } from "vitest";-injectGlobals();+// Top level, not in a beforeAll: vi.mock is hoisted either way, and nesting it only makes the order lie.+vi.mock("../services/ws.js", mockWebsocket);+vi.mock("../services/server.js", mockServer);-beforeAll(() => {- vi.mock("../services/ws.js", mockWebsocket);- vi.mock("../services/server.js", mockServer);-});+injectGlobals();function injectGlobals() {const uncheckedWindow = window as any;diff --git a/apps/client/src/widgets/ribbon/NoteInfoTab.spec.tsx b/apps/client/src/widgets/ribbon/NoteInfoTab.spec.tsxindex 3ddd0a2503..f1faedd2d3 100644--- a/apps/client/src/widgets/ribbon/NoteInfoTab.spec.tsx+++ b/apps/client/src/widgets/ribbon/NoteInfoTab.spec.tsx@@ -6,7 +6,9 @@ import { afterEach, describe, expect, it, vi } from "vitest";const mocks = vi.hoisted(() => ({// Hoisted rather than a plain const: app_context pulls the server service in at module scope, so the// factory below runs before this file's own top-level statements do.- serverGet: vi.fn<(url: string) => Promise<unknown>>(async () => ({})),+ // Replacing the module also replaces the shared mock from test/setup.ts, so unrelated module-scope+ // loads have to be answered here too: keyboard_actions.ts filters the response as it imports.+ serverGet: vi.fn<(url: string) => Promise<unknown>>(async (url) => (url === "keyboard-actions" ? [] : {})),entitiesReloadedHandler: undefined as ((data: { loadResults: unknown }) => void) | undefined}));const serverGet = mocks.serverGet;