99 waitFor ,
1010 check ,
1111} from 'next-test-utils'
12- import webdriver from 'next-webdriver'
12+ import webdriver , { BrowserInterface } from 'next-webdriver'
1313import path from 'path'
1414import { nextTestSetup } from 'e2e-utils'
1515
@@ -56,12 +56,25 @@ describe('Client Navigation', () => {
5656 await browser . close ( )
5757 } )
5858
59- it ( 'should have proper error when no children are provided' , async ( ) => {
60- const browser = await webdriver ( next . appPort , '/link-no-child' )
59+ it ( 'should have a redbox when no children are provided' , async ( ) => {
60+ const pageErrors : unknown [ ] = [ ]
61+ const browser = await webdriver ( next . appPort , '/link-no-child' , {
62+ beforePageLoad : ( page ) => {
63+ page . on ( 'pageerror' , ( error : unknown ) => {
64+ pageErrors . push ( error )
65+ } )
66+ } ,
67+ } )
6168 await assertHasRedbox ( browser )
6269 expect ( await getRedboxHeader ( browser ) ) . toContain (
6370 'No children were passed to <Link> with `href` of `/about` but one child is required'
6471 )
72+ expect ( pageErrors ) . toEqual ( [
73+ expect . objectContaining ( {
74+ message :
75+ 'No children were passed to <Link> with `href` of `/about` but one child is required https://nextjs.org/docs/messages/link-no-children' ,
76+ } ) ,
77+ ] )
6578 } )
6679
6780 it ( 'should not throw error when one number type child is provided' , async ( ) => {
@@ -277,15 +290,28 @@ describe('Client Navigation', () => {
277290 } )
278291
279292 describe ( 'with empty getInitialProps()' , ( ) => {
280- it ( 'should render an error ' , async ( ) => {
281- let browser
293+ it ( 'should render a redbox ' , async ( ) => {
294+ let browser : BrowserInterface
282295 try {
283- browser = await webdriver ( next . appPort , '/nav' )
296+ const pageErrors : unknown [ ] = [ ]
297+ browser = await webdriver ( next . appPort , '/nav' , {
298+ beforePageLoad : ( page ) => {
299+ page . on ( 'pageerror' , ( error : unknown ) => {
300+ pageErrors . push ( error )
301+ } )
302+ } ,
303+ } )
284304 await browser . elementByCss ( '#empty-props' ) . click ( )
285305 await assertHasRedbox ( browser )
286306 expect ( await getRedboxHeader ( browser ) ) . toMatch (
287307 / s h o u l d r e s o l v e t o a n o b j e c t \. B u t f o u n d " n u l l " i n s t e a d \. /
288308 )
309+ expect ( pageErrors ) . toEqual ( [
310+ expect . objectContaining ( {
311+ message :
312+ '"EmptyInitialPropsPage.getInitialProps()" should resolve to an object. But found "null" instead.' ,
313+ } ) ,
314+ ] )
289315 } finally {
290316 if ( browser ) {
291317 await browser . close ( )
@@ -1377,13 +1403,39 @@ describe('Client Navigation', () => {
13771403
13781404 describe ( 'runtime errors' , ( ) => {
13791405 it ( 'should show redbox when a client side error is thrown inside a component' , async ( ) => {
1380- let browser
1406+ const isReact18 = process . env . NEXT_TEST_REACT_VERSION ?. startsWith ( '18' )
1407+ let browser : BrowserInterface
13811408 try {
1382- browser = await webdriver ( next . appPort , '/error-inside-browser-page' )
1409+ const pageErrors : unknown [ ] = [ ]
1410+ browser = await webdriver ( next . appPort , '/error-inside-browser-page' , {
1411+ beforePageLoad : ( page ) => {
1412+ page . on ( 'pageerror' , ( error : unknown ) => {
1413+ pageErrors . push ( error )
1414+ } )
1415+ } ,
1416+ } )
13831417 await assertHasRedbox ( browser )
13841418 const text = await getRedboxSource ( browser )
13851419 expect ( text ) . toMatch ( / A n E x p e c t e d e r r o r o c c u r r e d / )
13861420 expect ( text ) . toMatch ( / p a g e s [ \\ / ] e r r o r - i n s i d e - b r o w s e r - p a g e \. j s \( 5 : 1 3 \) / )
1421+
1422+ expect ( pageErrors ) . toEqual (
1423+ isReact18
1424+ ? [
1425+ expect . objectContaining ( {
1426+ message : 'An Expected error occurred' ,
1427+ } ) ,
1428+ expect . objectContaining ( {
1429+ message : 'An Expected error occurred' ,
1430+ } ) ,
1431+ expect . objectContaining ( {
1432+ message :
1433+ 'There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.' ,
1434+ } ) ,
1435+ ]
1436+ : // TODO(veil): Should contain thrown error
1437+ [ ]
1438+ )
13871439 } finally {
13881440 if ( browser ) {
13891441 await browser . close ( )
@@ -1392,16 +1444,27 @@ describe('Client Navigation', () => {
13921444 } )
13931445
13941446 it ( 'should show redbox when a client side error is thrown outside a component' , async ( ) => {
1395- let browser
1447+ let browser : BrowserInterface
13961448 try {
1449+ const pageErrors : unknown [ ] = [ ]
13971450 browser = await webdriver (
13981451 next . appPort ,
1399- '/error-in-the-browser-global-scope'
1452+ '/error-in-the-browser-global-scope' ,
1453+ {
1454+ beforePageLoad : ( page ) => {
1455+ page . on ( 'pageerror' , ( error : unknown ) => {
1456+ pageErrors . push ( error )
1457+ } )
1458+ } ,
1459+ }
14001460 )
14011461 await assertHasRedbox ( browser )
14021462 const text = await getRedboxSource ( browser )
14031463 expect ( text ) . toMatch ( / A n E x p e c t e d e r r o r o c c u r r e d / )
14041464 expect ( text ) . toMatch ( / e r r o r - i n - t h e - b r o w s e r - g l o b a l - s c o p e \. j s \( 2 : 9 \) / )
1465+ expect ( pageErrors ) . toEqual ( [
1466+ expect . objectContaining ( { message : 'An Expected error occurred' } ) ,
1467+ ] )
14051468 } finally {
14061469 if ( browser ) {
14071470 await browser . close ( )
0 commit comments