Skip to content
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

Add test for link to catchall route in new router #41289

Merged
merged 1 commit into from Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions test/e2e/app-dir/app/app/catch-all-link/page.js
@@ -0,0 +1,18 @@
import Link from 'next/link'

export default function Page() {
return (
<>
<div>
<Link href="/catch-all/this/is/a/test">
<a id="to-catch-all">To catch-all</a>
</Link>
</div>
<div>
<Link href="/catch-all-optional/this/is/a/test">
<a id="to-catch-all-optional">To optional catch-all</a>
</Link>
</div>
</>
)
}
@@ -1,7 +1,7 @@
export default function Page({ params }) {
return (
<h1 id="text" data-params={params.slug?.join('/') ?? ''}>
hello from /optional-catch-all/{params.slug?.join('/')}
hello from /catch-all-optional/{params.slug?.join('/')}
</h1>
)
}
26 changes: 24 additions & 2 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -639,18 +639,29 @@ describe('app dir', () => {
const route = params.join('/')
const html = await renderViaHTTP(
next.url,
`/optional-catch-all/${route}`
`/catch-all-optional/${route}`
)
const $ = cheerio.load(html)
expect($('#text').attr('data-params')).toBe(route)
})

it('should handle optional segments root', async () => {
const html = await renderViaHTTP(next.url, `/optional-catch-all`)
const html = await renderViaHTTP(next.url, `/catch-all-optional`)
const $ = cheerio.load(html)
expect($('#text').attr('data-params')).toBe('')
})

it('should handle optional catch-all segments link', async () => {
const browser = await webdriver(next.url, '/catch-all-link')
expect(
await browser
.elementByCss('#to-catch-all-optional')
.click()
.waitForElementByCss('#text')
.text()
).toBe(`hello from /catch-all-optional/this/is/a/test`)
})

it('should handle required segments', async () => {
const params = ['this', 'is', 'a', 'test']
const route = params.join('/')
Expand All @@ -668,6 +679,17 @@ describe('app dir', () => {
expect(res.status).toBe(404)
expect(await res.text()).toContain('This page could not be found')
})

it('should handle catch-all segments link', async () => {
const browser = await webdriver(next.url, '/catch-all-link')
expect(
await browser
.elementByCss('#to-catch-all')
.click()
.waitForElementByCss('#text')
.text()
).toBe(`hello from /catch-all/this/is/a/test`)
})
})

describe('should serve client component', () => {
Expand Down