Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(views): use fake timers globally in login-page tests to prevent input-otp timer leak (#642)
Bohan Jiang6b8afb1d3df4
diff --git a/packages/views/auth/login-page.test.tsx b/packages/views/auth/login-page.test.tsxindex 263af530f2..000503e00b 100644--- a/packages/views/auth/login-page.test.tsx+++ b/packages/views/auth/login-page.test.tsx@@ -1,12 +1,7 @@-import { describe, it, expect, vi, beforeEach } from "vitest";+import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";import { render, screen, waitFor, act } from "@testing-library/react";import userEvent from "@testing-library/user-event";-// jsdom doesn't provide elementFromPoint; input-otp calls it on a timer.-if (typeof document.elementFromPoint !== "function") {- document.elementFromPoint = () => null;-}-// ---------------------------------------------------------------------------// Hoisted mocks// ---------------------------------------------------------------------------@@ -83,6 +78,7 @@ describe("LoginPage", () => {const onSuccess = vi.fn();beforeEach(() => {+ vi.useFakeTimers({ shouldAdvanceTime: true });vi.clearAllMocks();// Default: no existing sessionlocalStorage.clear();@@ -93,6 +89,10 @@ describe("LoginPage", () => {});});+ afterEach(() => {+ vi.useRealTimers();+ });+// -------------------------------------------------------------------------// Email step rendering// -------------------------------------------------------------------------@@ -315,8 +315,6 @@ describe("LoginPage", () => {});it("calls sendCode again when resend is clicked after cooldown", async () => {- vi.useFakeTimers({ shouldAdvanceTime: true });-mockSendCode.mockResolvedValue(undefined);render(<LoginPage onSuccess={onSuccess} />);@@ -348,8 +346,6 @@ describe("LoginPage", () => {await user.click(resendBtn);expect(mockSendCode).toHaveBeenCalledTimes(2);-- vi.useRealTimers();});// -------------------------------------------------------------------------