diff --git a/plugins/fusion-plugin-reports/src/dashboard/test-setup.ts b/plugins/fusion-plugin-reports/src/dashboard/test-setup.ts index 9d53dd2c3..a90051000 100644 --- a/plugins/fusion-plugin-reports/src/dashboard/test-setup.ts +++ b/plugins/fusion-plugin-reports/src/dashboard/test-setup.ts @@ -1,5 +1,13 @@ import "@testing-library/jest-dom/vitest"; -import { vi } from "vitest"; +import { cleanup } from "@testing-library/react"; +import { afterEach, vi } from "vitest"; + +// @testing-library/react only auto-registers cleanup when vitest globals are +// enabled. We don't enable globals here, so we wire it manually — otherwise +// React leaves the test tree mounted, its scheduler fires a deferred update +// via setImmediate after the jsdom environment is torn down, and the suite +// fails with "ReferenceError: window is not defined". +afterEach(() => cleanup()); if (typeof window !== "undefined") { Object.defineProperty(window, "matchMedia", {