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

Test that adding query can be detected by useSearchParams #43969

Merged
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
8 changes: 8 additions & 0 deletions test/e2e/app-dir/navigation-and-querystring/app/layout.tsx
@@ -0,0 +1,8 @@
export default function Layout({ children }) {
return (
<html>
<head></head>
<body>{children}</body>
</html>
)
}
16 changes: 16 additions & 0 deletions test/e2e/app-dir/navigation-and-querystring/app/page.tsx
@@ -0,0 +1,16 @@
'use client'

import Link from 'next/link'
import { useSearchParams } from 'next/navigation'

export default function Page() {
const params = useSearchParams()
return (
<>
<Link id="set-query" href="/?a=b&c=d">
set Query
</Link>
<div id="query">{params.toString()}</div>
</>
)
}
@@ -0,0 +1,38 @@
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import webdriver from 'next-webdriver'
import { waitFor } from 'next-test-utils'

describe('app-dir navigation and querystring', () => {
let next: NextInstance

beforeAll(async () => {
next = await createNext({
files: new FileRef(__dirname),
dependencies: {
react: 'latest',
'react-dom': 'latest',
typescript: 'latest',
'@types/react': 'latest',
'@types/node': 'latest',
},
})
})
afterAll(() => next.destroy())

it('should set query correctly', async () => {
const browser = await webdriver(next.url, '/')
expect(await browser.elementById('query').text()).toMatchInlineSnapshot(
`""`
)

browser.elementById('set-query').click()
await waitFor(200)

expect(await browser.elementById('query').text()).toMatchInlineSnapshot(
`"a=b&c=d"`
)
const url = new URL(await browser.url())
expect(url.searchParams.toString()).toMatchInlineSnapshot(`"a=b&c=d"`)
})
})
5 changes: 5 additions & 0 deletions test/e2e/app-dir/navigation-and-querystring/next.config.js
@@ -0,0 +1,5 @@
module.exports = {
experimental: {
appDir: true,
},
}