Skip to content

Commit

Permalink
fix component to suspend
Browse files Browse the repository at this point in the history
  • Loading branch information
MatanBobi committed Dec 22, 2024
1 parent 8716744 commit 9999e1e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 58 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@
},
"devDependencies": {
"@antfu/eslint-config": "^2.24.1",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.3.0",
"@types/react": "^19.0.1",
"@types/react-dom": "^19.0.2",
"@vitejs/plugin-react": "^4.3.3",
"@vitest/browser": "^2.1.0",
"bumpp": "^9.4.2",
"changelogithub": "^0.13.9",
"eslint": "^9.8.0",
"playwright": "^1.46.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"tsup": "^8.2.4",
"tsx": "^4.17.0",
"typescript": "^5.5.4",
Expand Down
87 changes: 35 additions & 52 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions test/fixtures/SuspendedHelloWorld.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { use } from 'react'

let fakeCacheLoaded = false
const fakeCacheLoadPromise = new Promise<void>((resolve) => {
setTimeout(() => {
fakeCacheLoaded = true
resolve()
}, 100)
})

export function SuspendedHelloWorld({ name }: { name: string }): React.ReactElement {
if (!fakeCacheLoaded) {
use(fakeCacheLoadPromise)
}

return (
<div>{`Hello ${name}`}</div>
)
}
6 changes: 4 additions & 2 deletions test/render.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { page } from '@vitest/browser/context'
import { render } from '../src/index'
import { HelloWorld } from './fixtures/HelloWorld'
import { Counter } from './fixtures/Counter'
import { SuspendedHelloWorld } from './fixtures/SuspendedHelloWorld'

test('renders simple component', async () => {
const screen = await render(<HelloWorld />)
Expand All @@ -19,11 +20,12 @@ test('renders counter', async () => {
await expect.element(screen.getByText('Count is 2')).toBeVisible()
})

test('renders child component on mount for suspense boundary which is not suspending', async () => {
const { getByText } = await render(<HelloWorld name="Vitest" />, {
test('waits for suspended boundaries', async () => {
const { getByText } = await render(<SuspendedHelloWorld name="Vitest" />, {
wrapper: ({ children }) => (
<Suspense fallback={<div>Suspended!</div>}>{children}</Suspense>
),
})
await expect.element(getByText('Suspended!')).toBeInTheDocument()

Check failure on line 29 in test/render.test.tsx

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

test/render.test.tsx > waits for suspended boundaries

Error: Matcher did not succeed in 1000ms ❯ test/render.test.tsx:29:48 Caused by: Caused by: VitestBrowserElementError: Cannot find element with locator: locator('body').getByText('Suspended!') <body> <div> <div> Hello Vitest </div> </div> </body>

Check failure on line 29 in test/render.test.tsx

View workflow job for this annotation

GitHub Actions / test (macos-14, 20)

test/render.test.tsx > waits for suspended boundaries

Error: Matcher did not succeed in 1000ms ❯ test/render.test.tsx:29:48 Caused by: Caused by: VitestBrowserElementError: Cannot find element with locator: locator('body').getByText('Suspended!') <body> <div> <div> Hello Vitest </div> </div> </body>

Check failure on line 29 in test/render.test.tsx

View workflow job for this annotation

GitHub Actions / test (windows-latest, 20)

test/render.test.tsx > waits for suspended boundaries

Error: Matcher did not succeed in 1000ms ❯ test/render.test.tsx:29:48 Caused by: Caused by: VitestBrowserElementError: Cannot find element with locator: locator('body').getByText('Suspended!') <body> <div> <div> Hello Vitest </div> </div> </body>
await expect.element(getByText('Hello Vitest')).toBeInTheDocument()
})

0 comments on commit 9999e1e

Please sign in to comment.