Unverified Commit ab123c1e authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Add test for next-found and redirect for metadata (#46248)

Add tests for using `redirect` and `notFound` in `generateMetadata`
parent aac3ecb2
......@@ -7,3 +7,5 @@ export async function generateMetadata() {
keywords: 'parent',
}
}
export const revalidate = 0
import { notFound } from 'next/navigation'
export default function page() {
return 'not found'
return 'not-found-text'
}
export async function generateMetadata() {
......
import { redirect } from 'next/navigation'
export default function page() {
return 'redirect to basic'
}
export async function generateMetadata() {
redirect('/basic')
}
......@@ -330,6 +330,17 @@ createNextDescribe(
)
})
it('should support notFound and redirect in generateMetadata', async () => {
const resNotFound = await next.fetch('/async/not-found')
expect(resNotFound.status).toBe(404)
const notFoundHtml = await resNotFound.text()
expect(notFoundHtml).not.toBe('not-found-text')
expect(notFoundHtml).toContain('This page could not be found.')
const resRedirect = await next.fetch('/async/redirect')
expect(resRedirect.status).toBe(307)
})
if (isNextDev) {
it('should freeze parent resolved metadata to avoid mutating in generateMetadata', async () => {
const pagePath = 'app/mutate/page.tsx'
......
export const revalidate = 0
export const dynamic = 'force-dynamic'
export default function Layout({ children }) {
return (
......
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