File tree Expand file tree Collapse file tree 3 files changed +77
-0
lines changed
test/integration/error-in-error-client Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ import React from 'react'
2+
3+ class Error extends React . Component {
4+ static async getInitialProps ( { res, err } ) {
5+ const statusCode = res ? res . statusCode : err ? err . statusCode : null
6+ return { statusCode }
7+ }
8+
9+ render ( ) {
10+ if ( typeof window !== 'undefined' ) {
11+ throw new Error ( 'Error from Error page' )
12+ }
13+ return (
14+ < p >
15+ { this . props . statusCode
16+ ? `An error ${ this . props . statusCode } occurred on server`
17+ : 'An error occurred on client' }
18+ </ p >
19+ )
20+ }
21+ }
22+
23+ export default Error
Original file line number Diff line number Diff line change 1+ import Link from 'next/link'
2+
3+ function Index ( ) {
4+ return (
5+ < >
6+ < h3 > Hi 👋</ h3 >
7+ < Link href = "/a-non-existing-page" >
8+ < a > a link to no-where</ a >
9+ </ Link >
10+ </ >
11+ )
12+ }
13+
14+ Index . getInitialProps = ( ) => {
15+ if ( typeof window !== 'undefined' ) {
16+ throw new Error ( 'Error from Index page' )
17+ }
18+ return { }
19+ }
20+
21+ export default Index
Original file line number Diff line number Diff line change 1+ /* eslint-env jest */
2+
3+ import path from 'path'
4+ import webdriver from 'next-webdriver'
5+ import {
6+ nextBuild ,
7+ nextStart ,
8+ findPort ,
9+ killApp ,
10+ waitFor ,
11+ } from 'next-test-utils'
12+
13+ jest . setTimeout ( 1000 * 60 * 1 )
14+ const appDir = path . join ( __dirname , '..' )
15+ let app
16+ let port
17+
18+ describe ( 'Handles an Error in _error' , ( ) => {
19+ beforeAll ( async ( ) => {
20+ await nextBuild ( appDir )
21+ port = await findPort ( )
22+ app = await nextStart ( appDir , port )
23+ } )
24+ afterAll ( ( ) => killApp ( app ) )
25+
26+ it ( 'Handles error during client transition' , async ( ) => {
27+ const browser = await webdriver ( port , '/' )
28+ await browser . waitForElementByCss ( 'a' ) . click ( )
29+ await waitFor ( 1000 )
30+ const html = await browser . eval ( 'document.body.innerHTML' )
31+ expect ( html ) . toMatch ( / i n t e r n a l s e r v e r e r r o r / i)
32+ } )
33+ } )
You can’t perform that action at this time.
0 commit comments