Add tests for searchParams dev warning (#16798)
Fixes a warning being logged to the console when using `href` with a dynamic path. Fixes #16794
This commit is contained in:
parent
764b194505
commit
08859275ae
3 changed files with 54 additions and 0 deletions
9
test/integration/dynamic-routing/pages/d/[id].js
Normal file
9
test/integration/dynamic-routing/pages/d/[id].js
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { useRouter } from 'next/router'
|
||||
|
||||
const Page = () => {
|
||||
const router = useRouter()
|
||||
const { query } = router
|
||||
return <p id="asdf">This is {query.id}</p>
|
||||
}
|
||||
|
||||
export default Page
|
|
@ -1,6 +1,15 @@
|
|||
import Link from 'next/link'
|
||||
import { useRouter } from 'next/router'
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.caughtWarns = []
|
||||
const origWarn = window.console.warn
|
||||
window.console.warn = function (...args) {
|
||||
window.caughtWarns.push(args)
|
||||
origWarn(...args)
|
||||
}
|
||||
}
|
||||
|
||||
const Page = () => {
|
||||
return (
|
||||
<div>
|
||||
|
@ -128,6 +137,9 @@ const Page = () => {
|
|||
<a id="nested-ssg-catch-all-multi">Nested Catch-all route (multi)</a>
|
||||
</Link>
|
||||
<br />
|
||||
<Link href="/d/dynamic-1">
|
||||
<a id="dynamic-route-no-as">Dynamic route no as</a>
|
||||
</Link>
|
||||
<p id="query">{JSON.stringify(Object.keys(useRouter().query))}</p>
|
||||
</div>
|
||||
)
|
||||
|
|
|
@ -84,6 +84,31 @@ function runTests(dev) {
|
|||
expect(url).toBe('?fromHome=true')
|
||||
})
|
||||
|
||||
if (dev) {
|
||||
it('should not have any console warnings on initial load', async () => {
|
||||
const browser = await webdriver(appPort, '/')
|
||||
expect(await browser.eval('window.caughtWarns')).toEqual([])
|
||||
})
|
||||
|
||||
it('should not have any console warnings when navigating to dynamic route', async () => {
|
||||
let browser
|
||||
try {
|
||||
browser = await webdriver(appPort, '/')
|
||||
await browser.eval('window.beforeNav = 1')
|
||||
await browser.elementByCss('#dynamic-route-no-as').click()
|
||||
await browser.waitForElementByCss('#asdf')
|
||||
|
||||
expect(await browser.eval('window.beforeNav')).toBe(1)
|
||||
|
||||
const text = await browser.elementByCss('#asdf').text()
|
||||
expect(text).toMatch(/this is.*?dynamic-1/i)
|
||||
expect(await browser.eval('window.caughtWarns')).toEqual([])
|
||||
} finally {
|
||||
if (browser) await browser.close()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
it('should navigate to a dynamic page successfully', async () => {
|
||||
let browser
|
||||
try {
|
||||
|
@ -893,6 +918,14 @@ function runTests(dev) {
|
|||
helloworld: 'hello-world',
|
||||
},
|
||||
},
|
||||
{
|
||||
namedRegex: '^/d/(?<id>[^/]+?)(?:/)?$',
|
||||
page: '/d/[id]',
|
||||
regex: normalizeRegEx('^\\/d\\/([^\\/]+?)(?:\\/)?$'),
|
||||
routeKeys: {
|
||||
id: 'id',
|
||||
},
|
||||
},
|
||||
{
|
||||
namedRegex: '^/dash/(?<helloworld>[^/]+?)(?:/)?$',
|
||||
page: '/dash/[hello-world]',
|
||||
|
|
Loading…
Reference in a new issue