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
client: fix an issue
Adorian Doran9dcd431a31a6
diff --git a/apps/client/src/test/setup.ts b/apps/client/src/test/setup.tsindex b21692d788..feb0193325 100644--- a/apps/client/src/test/setup.ts+++ b/apps/client/src/test/setup.ts@@ -1,3 +1,4 @@+import { Modal } from "bootstrap";import $ from "jquery";import { vi } from "vitest";@@ -6,6 +7,7 @@ vi.mock("../services/ws.js", mockWebsocket);vi.mock("../services/server.js", mockServer);injectGlobals();+survivePendingModalCallbacks();function injectGlobals() {const uncheckedWindow = window as any;@@ -19,6 +21,28 @@ function injectGlobals() {};}+/**+ * Keeps a disposed modal readable by the callbacks Bootstrap has already queued.+ *+ * `dispose()` nulls every property (twbs/bootstrap#37474) while the end of the opening is still+ * waiting on a `transitionend` that happy-dom never fires, so it runs against a disposed instance+ * some milliseconds later and throws where no test can catch it. A teardown that disposes a modal+ * is how a spec releases the focus trap, so leave values those callbacks can read.+ */+function survivePendingModalCallbacks() {+ const proto = Modal.prototype as unknown as Record<string, unknown>;+ const dispose = proto.dispose as () => void;++ proto.dispose = function (this: Record<string, unknown>) {+ dispose.call(this);+ this._config = { focus: false, backdrop: false, keyboard: false };+ this._element = document.createElement("noscript");+ this._dialog = this._element;+ this._focustrap = { activate() {}, deactivate() {} };+ this._backdrop = { show() {}, hide() {}, dispose() {} };+ };+}+function mockWebsocket() {function subscribeToMessages(_callback: (message: unknown) => void) {// Do nothing.