Skip to content

Commit

Permalink
test: add test to check for suspended component
Browse files Browse the repository at this point in the history
  • Loading branch information
MatanBobi committed Dec 17, 2024
1 parent 61faa9f commit 6c9238b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions test/fixtures/HelloWorld.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export function HelloWorld(): React.ReactElement {
return <div>Hello World</div>
export function HelloWorld({
name = 'World',
}: {
name?: string
}): React.ReactElement {
return <div>{`Hello ${name}`}</div>
}
10 changes: 10 additions & 0 deletions test/render.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Suspense } from 'react'
import { expect, test } from 'vitest'
import { page } from '@vitest/browser/context'
import { render } from '../src/index'
Expand All @@ -17,3 +18,12 @@ test('renders counter', async () => {
await screen.getByRole('button', { name: 'Increment' }).click()
await expect.element(screen.getByText('Count is 2')).toBeVisible()
})

test('renders a suspended component', async () => {
const { getByText } = await render(<HelloWorld name="Vitest" />, {
wrapper: ({ children }) => (
<Suspense fallback={<div>Suspended!</div>}>{children}</Suspense>
),
})
await expect.element(getByText('Hello Vitest')).toBeInTheDocument()
})

0 comments on commit 6c9238b

Please sign in to comment.