Skip to content

Commit

Permalink
Add back/forward test for new router (vercel#41590)
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens authored and Kikobeats committed Oct 24, 2022
1 parent 18c916a commit 59f3b96
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/e2e/app-dir/app/app/back-forward/[id]/page.js
@@ -0,0 +1,24 @@
'use client'
import Link from 'next/link'
import { useRouter } from 'next/navigation'

export default function Page({ params }) {
const router = useRouter()
return (
<>
<h1 id={`message-${params.id}`}>Hello from {params.id}</h1>
<Link
href={params.id === '1' ? '/back-forward/2' : '/back-forward/1'}
id="to-other-page"
>
Go to {params.id === '1' ? '2' : '1'}
</Link>
<button onClick={() => router.back()} id="back-button">
Back
</button>
<button onClick={() => router.forward()} id="forward-button">
Forward
</button>
</>
)
}
36 changes: 36 additions & 0 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -913,6 +913,42 @@ describe('app dir', () => {
await browser.close()
}
})

it('should support router.back and router.forward', async () => {
const browser = await webdriver(next.url, '/back-forward/1')

const firstMessage = 'Hello from 1'
const secondMessage = 'Hello from 2'

expect(await browser.elementByCss('#message-1').text()).toBe(
firstMessage
)

try {
const message2 = await browser
.waitForElementByCss('#to-other-page')
.click()
.waitForElementByCss('#message-2')
.text()
expect(message2).toBe(secondMessage)

const message1 = await browser
.waitForElementByCss('#back-button')
.click()
.waitForElementByCss('#message-1')
.text()
expect(message1).toBe(firstMessage)

const message2Again = await browser
.waitForElementByCss('#forward-button')
.click()
.waitForElementByCss('#message-2')
.text()
expect(message2Again).toBe(secondMessage)
} finally {
await browser.close()
}
})
})

describe('hooks', () => {
Expand Down

0 comments on commit 59f3b96

Please sign in to comment.