Unverified Commit 425490c2 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

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

parent f7a7c3fa
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>
</>
)
}
export default function Page({ params }) { export default function Page({ params }) {
return ( return (
<h1 id="text" data-params={params.slug?.join('/') ?? ''}> <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> </h1>
) )
} }
...@@ -639,18 +639,29 @@ describe('app dir', () => { ...@@ -639,18 +639,29 @@ describe('app dir', () => {
const route = params.join('/') const route = params.join('/')
const html = await renderViaHTTP( const html = await renderViaHTTP(
next.url, next.url,
`/optional-catch-all/${route}` `/catch-all-optional/${route}`
) )
const $ = cheerio.load(html) const $ = cheerio.load(html)
expect($('#text').attr('data-params')).toBe(route) expect($('#text').attr('data-params')).toBe(route)
}) })
it('should handle optional segments root', async () => { 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) const $ = cheerio.load(html)
expect($('#text').attr('data-params')).toBe('') 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 () => { it('should handle required segments', async () => {
const params = ['this', 'is', 'a', 'test'] const params = ['this', 'is', 'a', 'test']
const route = params.join('/') const route = params.join('/')
...@@ -668,6 +679,17 @@ describe('app dir', () => { ...@@ -668,6 +679,17 @@ describe('app dir', () => {
expect(res.status).toBe(404) expect(res.status).toBe(404)
expect(await res.text()).toContain('This page could not be found') 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', () => { describe('should serve client component', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment