Unverified Commit 17716d14 authored by Jan Potoms's avatar Jan Potoms Committed by GitHub

Add tests for querystring-relative urls (#15911)

parent 5dbe0d02
import Link from 'next/link'
import { useRouter } from 'next/router'
export async function getServerSideProps({ query: { prop = '' } }) {
return { props: { prop } }
}
export default function Page({ prop }) {
const router = useRouter()
return (
<>
<div id="prop">{prop}</div>
<Link href="?prop=foo">
<a id="link">Click me</a>
</Link>
<button id="router-push" onClick={() => router.push('?prop=bar')}>
Push me
</button>
<button id="router-replace" onClick={() => router.replace('?prop=baz')}>
Push me
</button>
</>
)
}
......@@ -789,6 +789,41 @@ describe('Client Navigation', () => {
})
})
describe('with querystring relative urls', () => {
it('should work with Link', async () => {
const browser = await webdriver(context.appPort, '/nav/query-only')
try {
await browser.elementByCss('#link').click()
await check(() => browser.waitForElementByCss('#prop').text(), 'foo')
} finally {
await browser.close()
}
})
it('should work with router.push', async () => {
const browser = await webdriver(context.appPort, '/nav/query-only')
try {
await browser.elementByCss('#router-push').click()
await check(() => browser.waitForElementByCss('#prop').text(), 'bar')
} finally {
await browser.close()
}
})
it('should work with router.replace', async () => {
const browser = await webdriver(context.appPort, '/nav/query-only')
try {
await browser.elementByCss('#router-replace').click()
await check(() => browser.waitForElementByCss('#prop').text(), 'baz')
} finally {
await browser.close()
}
})
})
describe('with getInitialProp redirect', () => {
it('should redirect the page via client side', async () => {
const browser = await webdriver(context.appPort, '/nav')
......
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