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 back/forward test for new router #41590

Merged
merged 3 commits into from Oct 20, 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
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