Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
6 changed files
with
83 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,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> | ||
} |
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,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) |
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,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) |
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,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) |
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,9 @@ | ||
import Router from './Router' | ||
|
||
export default function Page() { | ||
return ( | ||
<div id="old-router"> | ||
<Router /> | ||
</div> | ||
) | ||
} |
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