forked from vercel/next.js
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test that adding query can be detected by useSearchParams (vercel#43969)
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function Layout({ children }) { | ||
return ( | ||
<html> | ||
<head></head> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> | ||
</> | ||
) | ||
} |
38 changes: 38 additions & 0 deletions
38
test/e2e/app-dir/navigation-and-querystring/navigation-and-querystring.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
experimental: { | ||
appDir: true, | ||
}, | ||
} |