Skip to content

Commit

Permalink
Add test for link to catchall route in new router (vercel#41289)
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens authored and Kikobeats committed Oct 24, 2022
1 parent a530788 commit 54f8c65
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
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

0 comments on commit 54f8c65

Please sign in to comment.