@@ -5067,13 +5067,19 @@ describe('shallow', () => {
50675067 class ErrorBoundary extends React . Component {
50685068 constructor ( ...args ) {
50695069 super ( ...args ) ;
5070- this . state = { throws : false } ;
5070+ this . state = {
5071+ throws : false ,
5072+ didThrow : false ,
5073+ } ;
50715074 }
50725075
50735076 componentDidCatch ( error , info ) {
50745077 const { spy } = this . props ;
50755078 spy ( error , info ) ;
5076- this . setState ( { throws : false } ) ;
5079+ this . setState ( {
5080+ throws : false ,
5081+ didThrow : true ,
5082+ } ) ;
50775083 }
50785084
50795085 render ( ) {
@@ -5083,6 +5089,9 @@ describe('shallow', () => {
50835089 < MaybeFragment >
50845090 < span >
50855091 < Thrower throws = { throws } />
5092+ < div >
5093+ { this . state . didThrow ? 'HasThrown' : 'HasNotThrown' }
5094+ </ div >
50865095 </ span >
50875096 </ MaybeFragment >
50885097 </ div >
@@ -5124,6 +5133,18 @@ describe('shallow', () => {
51245133 } ) ;
51255134 } ) ;
51265135
5136+ it ( 'rerenders on a simulated error' , ( ) => {
5137+ const wrapper = shallow ( < ErrorBoundary spy = { sinon . stub ( ) } /> ) ;
5138+
5139+ expect ( wrapper . find ( { children : 'HasThrown' } ) ) . to . have . lengthOf ( 0 ) ;
5140+ expect ( wrapper . find ( { children : 'HasNotThrown' } ) ) . to . have . lengthOf ( 1 ) ;
5141+
5142+ expect ( ( ) => wrapper . find ( Thrower ) . simulateError ( errorToThrow ) ) . not . to . throw ( ) ;
5143+
5144+ expect ( wrapper . find ( { children : 'HasThrown' } ) ) . to . have . lengthOf ( 1 ) ;
5145+ expect ( wrapper . find ( { children : 'HasNotThrown' } ) ) . to . have . lengthOf ( 0 ) ;
5146+ } ) ;
5147+
51275148 it ( 'does not catch errors during shallow render' , ( ) => {
51285149 const spy = sinon . spy ( ) ;
51295150 const wrapper = shallow ( < ErrorBoundary spy = { spy } /> ) ;
@@ -5141,6 +5162,9 @@ describe('shallow', () => {
51415162 expect ( ( ) => thrower . dive ( ) ) . to . throw ( errorToThrow ) ;
51425163
51435164 expect ( spy ) . to . have . property ( 'callCount' , 0 ) ;
5165+
5166+ expect ( wrapper . find ( { children : 'HasThrown' } ) ) . to . have . lengthOf ( 0 ) ;
5167+ expect ( wrapper . find ( { children : 'HasNotThrown' } ) ) . to . have . lengthOf ( 1 ) ;
51445168 } ) ;
51455169 } ) ;
51465170 } ) ;
0 commit comments