fix: Billing页面测试teardown后异步任务未清理,修复CI前端Lint失败 #600

Merged
auto-approve-bot merged 1 commits from fix/billing-test-teardown into develop 2026-07-19 17:24:53 +08:00
+16 -3
View File
@@ -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(
<MemoryRouter>
<Billing />
</MemoryRouter>,
)
// 跑完所有pending的timers和microtasks,确保异步状态更新都执行完
await act(async () => {
await vi.runAllTimersAsync()
})
expect(container).toBeTruthy()
})
})