File size: 1,939 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import { createNext } from 'e2e-utils'
import { NextInstance } from 'e2e-utils'
import { check, renderViaHTTP } from 'next-test-utils'
describe('custom-error-500', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
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: {},
})
})
afterAll(() => next.destroy())
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/)
})
})
|