Skip to content

Commit

Permalink
Also assert on req.url
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Feb 26, 2025
1 parent 88efc1a commit 5efc77e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions test/e2e/as-path-with-rewrites/as-path-with-rewrites.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ describe('as-path-with-rewrites', () => {
files: __dirname,
})

it('should not include internal query params in `asPath`', async () => {
it('should not include internal query params in `asPath` and `req.url`', async () => {
const $ = await next.render$('/foo')
expect($('h1').text()).toBe('rewrite-target: /foo')
expect($('#as-path').text()).toBe('/foo')
expect($('#req-url').text()).toBe('/foo')
})
})
14 changes: 10 additions & 4 deletions test/e2e/as-path-with-rewrites/pages/rewrite-target/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { GetServerSidePropsContext } from 'next'
import { useRouter } from 'next/router'

export async function getServerSideProps(context: GetServerSidePropsContext) {
return { props: {} }
export async function getServerSideProps({ req }: GetServerSidePropsContext) {
return { props: { url: req.url } }
}

export default function RewriteTarget() {
export default function RewriteTarget({ url }: { url: string }) {
const router = useRouter()

return <h1>rewrite-target: {router.asPath}</h1>
return (
<>
<h1>rewrite-target</h1>
<p id="as-path">{router.asPath}</p>
<p id="req-url">{url}</p>
</>
)
}

0 comments on commit 5efc77e

Please sign in to comment.