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

Added tests for next/router in app directory #39867

Merged
merged 4 commits into from Aug 23, 2022
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
7 changes: 7 additions & 0 deletions test/e2e/app-dir/app/app/old-router/IsNull.js
@@ -0,0 +1,7 @@
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>
}
15 changes: 15 additions & 0 deletions test/e2e/app-dir/app/app/old-router/Router.client.js
@@ -0,0 +1,15 @@
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)
19 changes: 19 additions & 0 deletions test/e2e/app-dir/app/app/old-router/Router.js
@@ -0,0 +1,19 @@
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)
15 changes: 15 additions & 0 deletions test/e2e/app-dir/app/app/old-router/Router.server.js
@@ -0,0 +1,15 @@
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)
9 changes: 9 additions & 0 deletions test/e2e/app-dir/app/app/old-router/page.server.js
@@ -0,0 +1,9 @@
import Router from './Router'

export default function Page() {
return (
<div id="old-router">
<Router />
</div>
)
}
18 changes: 18 additions & 0 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not compare the literal text?

} finally {
await browser.close()
}
})
})

describe('hooks', () => {
describe('useCookies', () => {
it('should retrive cookies in a server component', async () => {
Expand Down