@@ -782,6 +782,65 @@ export async function hasRedbox(browser: BrowserInterface): Promise<boolean> {
782782 return result
783783}
784784
785+ export async function assertHasRedbox ( browser : BrowserInterface ) {
786+ try {
787+ await retry (
788+ async ( ) => {
789+ const hasRedbox = await evaluate ( browser , ( ) => {
790+ return Boolean (
791+ [ ] . slice
792+ . call ( document . querySelectorAll ( 'nextjs-portal' ) )
793+ . find ( ( p ) =>
794+ p . shadowRoot . querySelector (
795+ '#nextjs__container_errors_label, #nextjs__container_errors_label'
796+ )
797+ )
798+ )
799+ } )
800+ expect ( hasRedbox ) . toBe ( true )
801+ } ,
802+ 5000 ,
803+ 200
804+ )
805+ } catch ( errorCause ) {
806+ const error = new Error ( 'Expected Redbox but found none' )
807+ Error . captureStackTrace ( error , assertHasRedbox )
808+ throw error
809+ }
810+ }
811+
812+ export async function assertNoRedbox ( browser : BrowserInterface ) {
813+ await waitFor ( 5000 )
814+ const hasRedbox = await evaluate ( browser , ( ) => {
815+ return Boolean (
816+ [ ] . slice
817+ . call ( document . querySelectorAll ( 'nextjs-portal' ) )
818+ . find ( ( p ) =>
819+ p . shadowRoot . querySelector (
820+ '#nextjs__container_errors_label, #nextjs__container_errors_label'
821+ )
822+ )
823+ )
824+ } )
825+
826+ if ( hasRedbox ) {
827+ const [ redboxHeader , redboxDescription , redboxSource ] = await Promise . all ( [
828+ getRedboxHeader ( browser ) . catch ( ( ) => '<missing>' ) ,
829+ getRedboxDescription ( browser ) . catch ( ( ) => '<missing>' ) ,
830+ getRedboxSource ( browser ) . catch ( ( ) => '<missing>' ) ,
831+ ] )
832+
833+ const error = new Error (
834+ 'Expected no Redbox but found one\n' +
835+ `header: ${ redboxHeader } \n` +
836+ `description: ${ redboxDescription } \n` +
837+ `source: ${ redboxSource } `
838+ )
839+ Error . captureStackTrace ( error , assertNoRedbox )
840+ throw error
841+ }
842+ }
843+
785844export async function hasErrorToast (
786845 browser : BrowserInterface
787846) : Promise < boolean > {
0 commit comments