@@ -485,6 +485,39 @@ test.describe('Events', () => {
485485 } )
486486 } )
487487
488+ test . describe ( 'httpException with Inertia error page response' , ( ) => {
489+ test ( 'it fires when the server returns a valid Inertia response with an error status code' , async ( { page } ) => {
490+ await listenForGlobalMessages ( page , 'inertia:httpException' )
491+ await clickAndWaitForResponse ( page , 'HTTP Exception Event (Inertia Response)' , 'inertia-error-page' )
492+
493+ const messages = await waitForMessages ( page , 5 )
494+ const globalMessages = await waitForGlobalMessages ( page , 'inertia:httpException' , 1 )
495+
496+ await assertIsGlobalEvent ( globalMessages [ 0 ] , 'inertia:httpException' , true )
497+
498+ await expect ( messages [ 0 ] ) . toBe ( 'onHttpException' )
499+ await expect ( messages [ 1 ] ) . toBe ( 'Inertia.on(httpException)' )
500+ await expect ( messages [ 3 ] ) . toBe ( 'addEventListener(inertia:httpException)' )
501+
502+ await expect ( page . locator ( '#status' ) ) . toContainText ( '500' )
503+ } )
504+
505+ test ( 'it suppresses the error page navigation when the visit callback returns false' , async ( { page } ) => {
506+ await listenForGlobalMessages ( page , 'inertia:httpException' )
507+ await clickAndWaitForResponse ( page , 'HTTP Exception Event (Inertia Response Prevent)' , 'inertia-error-page' )
508+
509+ const messages = await waitForMessages ( page , 2 )
510+ const globalMessages = await waitForGlobalMessages ( page , 'inertia:httpException' )
511+
512+ await expect ( messages [ 0 ] ) . toBe ( 'onHttpException' )
513+ await assertResponseObject ( messages [ 1 ] )
514+
515+ await expect ( globalMessages ) . toHaveLength ( 0 )
516+
517+ await expect ( page . locator ( '#status' ) ) . not . toBeVisible ( )
518+ } )
519+ } )
520+
488521 test . describe ( 'networkError' , ( ) => {
489522 test ( 'gets fired when an unexpected situation occurs (e.g. network disconnect)' , async ( { page } ) => {
490523 await listenForGlobalMessages ( page , 'inertia:networkError' , true )
0 commit comments