@@ -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,11 @@ describe('shallow', () => {
50835089 < MaybeFragment >
50845090 < span >
50855091 < Thrower throws = { throws } />
5092+ < div >
5093+ { this . state . didThrow ?
5094+ 'HasThrown' : 'HasNotThrown'
5095+ }
5096+ </ div >
50865097 </ span >
50875098 </ MaybeFragment >
50885099 </ div >
@@ -5124,6 +5135,18 @@ describe('shallow', () => {
51245135 } ) ;
51255136 } ) ;
51265137
5138+ it ( 'rerenders on a simulated error' , ( ) => {
5139+ const wrapper = shallow ( < ErrorBoundary spy = { sinon . stub ( ) } /> ) ;
5140+
5141+ expect ( wrapper . find ( { children : 'HasThrown' } ) ) . to . have . lengthOf ( 0 ) ;
5142+ expect ( wrapper . find ( { children : 'HasNotThrown' } ) ) . to . have . lengthOf ( 1 ) ;
5143+
5144+ expect ( ( ) => wrapper . find ( Thrower ) . simulateError ( errorToThrow ) ) . not . to . throw ( ) ;
5145+
5146+ expect ( wrapper . find ( { children : 'HasThrown' } ) ) . to . have . lengthOf ( 1 ) ;
5147+ expect ( wrapper . find ( { children : 'HasNotThrown' } ) ) . to . have . lengthOf ( 0 ) ;
5148+ } ) ;
5149+
51275150 it ( 'does not catch errors during shallow render' , ( ) => {
51285151 const spy = sinon . spy ( ) ;
51295152 const wrapper = shallow ( < ErrorBoundary spy = { spy } /> ) ;
@@ -5141,6 +5164,9 @@ describe('shallow', () => {
51415164 expect ( ( ) => thrower . dive ( ) ) . to . throw ( errorToThrow ) ;
51425165
51435166 expect ( spy ) . to . have . property ( 'callCount' , 0 ) ;
5167+
5168+ expect ( wrapper . find ( { children : 'HasThrown' } ) ) . to . have . lengthOf ( 0 ) ;
5169+ expect ( wrapper . find ( { children : 'HasNotThrown' } ) ) . to . have . lengthOf ( 1 ) ;
51445170 } ) ;
51455171 } ) ;
51465172 } ) ;
0 commit comments