Unverified Commit 9cc156c3 authored by Wyatt Johnson's avatar Wyatt Johnson Committed by GitHub

Added tests for next/router in app directory (#39867)

<!--
Thanks for opening a PR! Your contribution is much appreciated.
In order to make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

Added tests to ensure that the `next/router` returns null for `useRouter` and `withRouter` when used with the app directory.
parent 64a3697d
export default function IsNull({ value }) {
if (value === null) {
return <div className="was-null">Value Was Null</div>
}
return <div className="was-not-null">Value Was Not Null</div>
}
import { useRouter, withRouter } from 'next/router'
import IsNull from './IsNull'
function ClientRouter({ router: withRouter }) {
const router = useRouter()
return (
<>
<IsNull value={withRouter} />
<IsNull value={router} />
</>
)
}
export default withRouter(ClientRouter)
import { useRouter, withRouter } from 'next/router'
import IsNull from './IsNull'
import ServerRouter from './Router.server'
import ClientRouter from './Router.client'
function SharedRouter({ router: withRouter }) {
const router = useRouter()
return (
<>
<IsNull value={withRouter} />
<IsNull value={router} />
<ServerRouter />
<ClientRouter />
</>
)
}
export default withRouter(SharedRouter)
import { useRouter, withRouter } from 'next/router'
import IsNull from './IsNull'
function ServerRouter({ router: withRouter }) {
const router = useRouter()
return (
<>
<IsNull value={withRouter} />
<IsNull value={router} />
</>
)
}
export default withRouter(ServerRouter)
import Router from './Router'
export default function Page() {
return (
<div id="old-router">
<Router />
</div>
)
}
......@@ -720,6 +720,24 @@ describe('app dir', () => {
})
})
describe('next/router', () => {
it('should always return null when accessed from /app', async () => {
const browser = await webdriver(next.url, '/old-router')
try {
await browser.waitForElementByCss('#old-router')
const notNull = await browser.elementsByCss('.was-not-null')
expect(notNull.length).toBe(0)
const wasNull = await browser.elementsByCss('.was-null')
expect(wasNull.length).toBe(6)
} finally {
await browser.close()
}
})
})
describe('hooks', () => {
describe('useCookies', () => {
it('should retrive cookies in a server component', async () => {
......
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