fix(plugins/reports): wire @testing-library/react cleanup so React teardown doesn't leak past test env
The api stub from 43be32bbd silenced the fetch-rejection path but the suite
still failed on CI: the actual unhandled error is React's scheduler firing
deferred work via setImmediate after jsdom is torn down — its internal
render then dereferences `window` and throws ReferenceError. @testing-library
only auto-registers cleanup() when vitest `globals: true` is set, and this
package doesn't enable globals, so the React tree from each render() stays
mounted across teardown. Register cleanup manually in test-setup.ts so every
dashboard test unmounts its tree before the environment tears down.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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", {
|
||||
|
||||
Reference in New Issue
Block a user