Add test for catching metadata error in error boundaries (#53581)

This commit is contained in:
Jiachi Liu 2023-08-04 20:57:49 +02:00 committed by GitHub
parent ab14895ada
commit 99372fbedf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 0 deletions

View file

@ -0,0 +1,5 @@
'use client'
export default function Error() {
return <p id="error">Local error boundary</p>
}

View file

@ -0,0 +1,9 @@
export const dynamic = 'force-dynamic'
export function generateMetadata() {
throw new Error('Metadata error')
}
export default function Page() {
return <p>Metadata error</p>
}

View file

@ -0,0 +1,9 @@
export const dynamic = 'force-dynamic'
export function generateMetadata() {
throw new Error('Metadata error')
}
export default function Page() {
return <p>Metadata error</p>
}

View file

@ -57,5 +57,27 @@ createNextDescribe(
expect(await browser.hasElementByCssSelector('#digest')).toBeFalsy() expect(await browser.hasElementByCssSelector('#digest')).toBeFalsy()
} }
}) })
it('should catch metadata error in error boundary if presented', async () => {
const browser = await next.browser('/metadata-error-with-boundary')
expect(await browser.elementByCss('#error').text()).toBe(
'Local error boundary'
)
expect(await browser.hasElementByCssSelector('#digest')).toBeFalsy()
})
it('should catch metadata error in global-error if no error boundary is presented', async () => {
const browser = await next.browser('/metadata-error-without-boundary')
if (isNextDev) {
await testDev(browser, /Error: Metadata error/)
} else {
expect(await browser.elementByCss('h1').text()).toBe('Global Error')
expect(await browser.elementByCss('#error').text()).toBe(
'Global error: An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.'
)
}
})
} }
) )