diff --git a/apps/web/src/test/pages/Billing.test.tsx b/apps/web/src/test/pages/Billing.test.tsx old mode 100644 new mode 100755 index b825828de..7cf6aabf6 --- a/apps/web/src/test/pages/Billing.test.tsx +++ b/apps/web/src/test/pages/Billing.test.tsx @@ -1,5 +1,5 @@ -import { describe, expect, it, vi } from "vitest" -import { render } from "@testing-library/react" +import { describe, expect, it, vi, beforeEach, afterEach } from "vitest" +import { render, act, cleanup } from "@testing-library/react" import { MemoryRouter } from "react-router-dom" vi.mock("@/components/layout/PageHead", () => ({ @@ -13,12 +13,25 @@ vi.mock("@/components/layout/PageHead", () => ({ import Billing from "@/pages/subscription/Billing" describe("Billing Page", () => { - it("should render without crashing", () => { + beforeEach(() => { + vi.useFakeTimers() + }) + + afterEach(() => { + cleanup() + vi.useRealTimers() + }) + + it("should render without crashing", async () => { const { container } = render( , ) + // 跑完所有pending的timers和microtasks,确保异步状态更新都执行完 + await act(async () => { + await vi.runAllTimersAsync() + }) expect(container).toBeTruthy() }) })