Skip to content

feat: support async act v2 #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/pure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,14 @@ export async function renderHook<Props, Result>(renderCallback: (initialProps?:
}

export async function cleanup(): Promise<void> {
await Promise.all(
mountedRootEntries.map(async ({ root, container }) => {
for (const { root, container } of mountedRootEntries) {
await act(() => {
root.unmount()
})
if (container.parentNode === document.body) {
document.body.removeChild(container)
}
}),
)
}
mountedRootEntries.length = 0
mountedContainers.clear()
}
Expand Down
17 changes: 7 additions & 10 deletions test/render.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, beforeEach, expect, test, vi } from 'vitest'
import { expect, test, vi } from 'vitest'
import { page, userEvent } from '@vitest/browser/context'
import { Button } from 'react-aria-components'
import { Suspense } from 'react'
Expand All @@ -7,14 +7,6 @@ import { HelloWorld } from './fixtures/HelloWorld'
import { Counter } from './fixtures/Counter'
import { SuspendedHelloWorld } from './fixtures/SuspendedHelloWorld'

beforeEach(() => {
vi.useFakeTimers()
})

afterEach(() => {
vi.useRealTimers()
})

test('renders simple component', async () => {
const screen = await render(<HelloWorld />)
await expect.element(page.getByText('Hello World')).toBeVisible()
Expand All @@ -37,7 +29,8 @@ test('should fire the onPress/onClick handler', async () => {
expect(handler).toHaveBeenCalled()
})

test('waits for suspended boundaries', async () => {
test('waits for suspended boundaries', async ({ onTestFinished }) => {
vi.useFakeTimers()
const result = render(<SuspendedHelloWorld name="Vitest" />, {
wrapper: ({ children }) => (
<Suspense fallback={<div>Suspended!</div>}>{children}</Suspense>
Expand All @@ -47,4 +40,8 @@ test('waits for suspended boundaries', async () => {
vi.runAllTimers()
await result
await expect.element(page.getByText('Hello Vitest')).toBeInTheDocument()

onTestFinished(() => {
vi.useRealTimers()
})
})