@@ -77,6 +77,66 @@ it('guards against infinite render loops', () => {
7777 } )
7878} )
7979
80+ it ( 'returns to the next error boundary on a suspense error' , ( ) => {
81+ const Inner = jest . fn ( ( ) => null )
82+
83+ const Throw = jest . fn ( ( ) => {
84+ throw Promise . reject ( new Error ( 'Suspense!' ) )
85+ } )
86+
87+ class Outer extends Component {
88+ static getDerivedStateFromProps ( ) {
89+ return { error : false }
90+ }
91+
92+ static getDerivedStateFromError ( error ) {
93+ expect ( error ) . not . toBeInstanceOf ( Promise )
94+ return { error : true }
95+ }
96+
97+ render ( ) {
98+ return this . state . error ? < Inner /> : < Throw />
99+ }
100+ }
101+
102+ const render$ = renderPrepass ( < Outer /> )
103+ expect ( Throw ) . toHaveBeenCalledTimes ( 1 )
104+ expect ( Inner ) . not . toHaveBeenCalled ( )
105+
106+ return render$ . then ( ( ) => {
107+ expect ( Inner ) . toHaveBeenCalledTimes ( 1 )
108+ } )
109+ } )
110+
111+ it ( 'returns to the next error boundary on a nested error' , ( ) => {
112+ const Throw = jest . fn ( ( { depth } ) => {
113+ if ( depth >= 4 ) {
114+ throw new Error ( '' + depth )
115+ }
116+
117+ return < Throw depth = { depth + 1 } />
118+ } )
119+
120+ class Outer extends Component {
121+ static getDerivedStateFromProps ( ) {
122+ return { error : false }
123+ }
124+
125+ static getDerivedStateFromError ( error ) {
126+ expect ( error . message ) . toBe ( '4' )
127+ return { error : true }
128+ }
129+
130+ render ( ) {
131+ return ! this . state . error ? < Throw depth = { 1 } /> : null
132+ }
133+ }
134+
135+ renderPrepass ( < Outer /> ) . then ( ( ) => {
136+ expect ( Throw ) . toHaveBeenCalledTimes ( 4 )
137+ } )
138+ } )
139+
80140it ( 'always returns to the correct error boundary' , ( ) => {
81141 const values = [ ]
82142
0 commit comments