Fix unhandled "window is not defined" error in user_edit_view tests

Tremor's internal Tooltip component sets a setTimeout that fires after
the jsdom test environment tears down, causing a ReferenceError. Add
afterEach that flushes pending timers before cleanup.
This commit is contained in:
Yuneng Jiang 2026-04-10 00:10:40 -07:00
parent 9e6d2d2069
commit a771e1939c
No known key found for this signature in database

View file

@ -1,6 +1,6 @@
import { screen, waitFor } from "@testing-library/react";
import { cleanup, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { renderWithProviders } from "../../tests/test-utils";
import { UserEditView } from "./user_edit_view";
@ -140,6 +140,15 @@ describe("UserEditView", () => {
vi.clearAllMocks();
});
afterEach(() => {
// Tremor's internal Tooltip sets a setTimeout that fires after teardown,
// causing "window is not defined". Flush pending timers before cleanup.
vi.useFakeTimers();
vi.runAllTimers();
vi.useRealTimers();
cleanup();
});
it("should render", async () => {
renderWithProviders(<UserEditView {...defaultProps} />);