Skip to content

Commit 116998a

Browse files
committed
tests
1 parent 429bd31 commit 116998a

File tree

7 files changed

+82
-0
lines changed

7 files changed

+82
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function RootLayout({ children }: LayoutProps<'/'>) {
2+
return (
3+
<html>
4+
<head></head>
5+
<body>{children}</body>
6+
</html>
7+
)
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Link from 'next/link'
2+
3+
export default function Page() {
4+
return (
5+
<main>
6+
<h1>Home</h1>
7+
<Link href="/with-loading" prefetch={false}>
8+
Go to /with-loading (no prefetch)
9+
</Link>
10+
</main>
11+
)
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use client'
2+
3+
import { use } from 'react'
4+
5+
const infinitePromise = new Promise<never>(() => {})
6+
7+
export function SuspendForeverOnClient() {
8+
use(infinitePromise)
9+
return null
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Loading() {
2+
return <div id="loading-component">Loading...</div>
3+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { connection } from 'next/server'
2+
import { SuspendForeverOnClient } from './client'
3+
4+
export default async function Page() {
5+
await connection()
6+
return (
7+
<main>
8+
{/* Block on the client to make sure that the loading boundary works correctly. */}
9+
<SuspendForeverOnClient />
10+
</main>
11+
)
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/** @type {import('next').NextConfig} */
2+
module.exports = {
3+
experimental: {
4+
clientSegmentCache: true,
5+
clientParamParsing: true,
6+
},
7+
productionBrowserSourceMaps: true,
8+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
import { createRouterAct } from '../router-act'
3+
4+
describe('navigating without a prefetch', () => {
5+
const { next } = nextTestSetup({
6+
files: __dirname,
7+
})
8+
9+
it('can show a loading boundary from the dynamic response', async () => {
10+
let act: ReturnType<typeof createRouterAct>
11+
const browser = await next.browser('/', {
12+
beforePageLoad(page) {
13+
act = createRouterAct(page)
14+
},
15+
})
16+
17+
// Navigate to a dynamic page with a `loading.tsx` without a prefetch.
18+
await act(async () => {
19+
await browser.elementByCss('a[href="/with-loading"]').click()
20+
})
21+
22+
// The page suspends on the client, so we should display the `loading` that we got from the dynamic response.
23+
expect(
24+
await browser
25+
.elementByCss('#loading-component', { state: 'visible' })
26+
.text()
27+
).toContain('Loading...')
28+
})
29+
})

0 commit comments

Comments
 (0)