From 373cbec75248d218457158ce3e8657651775c906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=81=B5=E5=BA=94?= Date: Sun, 19 Jul 2026 17:14:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Billing=E9=A1=B5=E9=9D=A2=E6=B5=8B?= =?UTF-8?q?=E8=AF=95teardown=E5=90=8E=E5=BC=82=E6=AD=A5=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=9C=AA=E6=B8=85=E7=90=86=EF=BC=8C=E5=AF=BC=E8=87=B4window?= =?UTF-8?q?=E6=9C=AA=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/src/test/pages/Billing.test.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) mode change 100644 => 100755 apps/web/src/test/pages/Billing.test.tsx 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() }) }) -- 2.54.0