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): let Bootstrap's transition timers run out before teardown
Elian Doran976be46cea1b
diff --git a/apps/client/src/test/setup.ts b/apps/client/src/test/setup.tsindex f6d9397cda..5d5704d065 100644--- a/apps/client/src/test/setup.ts+++ b/apps/client/src/test/setup.ts@@ -5,7 +5,7 @@ import "preact/compat";import { Modal } from "bootstrap";import $ from "jquery";-import { vi } from "vitest";+import { afterAll, vi } from "vitest";// 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);@@ -13,6 +13,7 @@ vi.mock("../services/server.js", mockServer);injectGlobals();survivePendingModalCallbacks();+drainBootstrapTransitions();function injectGlobals() {const uncheckedWindow = window as any;@@ -131,3 +132,15 @@ function mockServer() {}};}++/**+ * Lets Bootstrap's transition timers run out before the file's environment is torn down.+ *+ * happy-dom runs no transitions, so Bootstrap ends each one with a `setTimeout()` of about 5ms that+ * dispatches `transitionend` itself. A file that ends with a dialog still opening or closing leaves+ * one pending, and once the window is gone its `new Event()` belongs to another realm than the+ * element, which throws outside any test.+ */+function drainBootstrapTransitions() {+ afterAll(() => new Promise((resolve) => setTimeout(resolve, 50)));+}