Add test for catching metadata error in error boundaries (#53581)
This commit is contained in:
parent
ab14895ada
commit
99372fbedf
4 changed files with 45 additions and 0 deletions
|
@ -0,0 +1,5 @@
|
||||||
|
'use client'
|
||||||
|
|
||||||
|
export default function Error() {
|
||||||
|
return <p id="error">Local error boundary</p>
|
||||||
|
}
|
|
@ -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>
|
||||||
|
}
|
|
@ -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>
|
||||||
|
}
|
|
@ -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.'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue