Files
4588a73542 Convert tests using createNext -> nextTestSetup (#93767)
## What?

Converts existing `createNext()` usage into `nextTestSetup()`. 

`createNext()` was the setup step we had before `nextTestSetup()` was
added.

This PR focused on the simple conversion cases. There will be a
follow-up to complete the last few.

---------

Co-authored-by: Cursor <[email protected]>
2026-05-12 13:16:31 +02:00

72 lines
1.7 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
import { check, renderViaHTTP } from 'next-test-utils'
describe('custom-error-500', () => {
const { next } = nextTestSetup({
files: {
'pages/index.js': `
export function getServerSideProps() {
throw new Error('custom error')
}
export default function Page() {
return <p>index page</p>
}
`,
'pages/500.js': `
export default function Custom500() {
return (
<>
<p>pages/500</p>
</>
)
}
`,
'pages/_error.js': `
function Error({ hasError }) {
return (
<>
<p>/_error</p>
</>
)
}
Error.getInitialProps = ({ err }) => {
console.log(\`called Error.getInitialProps \${!!err}\`)
return {
hasError: !!err
}
}
export default Error
`,
},
dependencies: {},
})
it('should correctly use pages/500 and call Error.getInitialProps', async () => {
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('pages/500')
await check(() => next.cliOutput, /called Error\.getInitialProps true/)
})
it('should work correctly with pages/404 present', async () => {
await next.stop()
await next.patchFile(
'pages/404.js',
`
export default function Page() {
return <p>custom 404 page</p>
}
`
)
await next.start()
const html = await renderViaHTTP(next.url, '/')
expect(html).toContain('pages/500')
await check(() => next.cliOutput, /called Error\.getInitialProps true/)
})
})