@@ -937,7 +937,7 @@ describe('ReactErrorBoundaries', () => {
937937 expect ( log ) . toEqual ( [ 'ErrorBoundary componentWillUnmount' ] ) ;
938938 } ) ;
939939
940- it ( 'resets refs if mounting aborts' , ( ) => {
940+ it ( 'resets callback refs if mounting aborts' , ( ) => {
941941 function childRef ( x ) {
942942 log . push ( 'Child ref is set to ' + x ) ;
943943 }
@@ -981,6 +981,44 @@ describe('ReactErrorBoundaries', () => {
981981 ] ) ;
982982 } ) ;
983983
984+ it ( 'resets object refs if mounting aborts' , ( ) => {
985+ let childRef = React . createRef ( ) ;
986+ let errorMessageRef = React . createRef ( ) ;
987+
988+ const container = document . createElement ( 'div' ) ;
989+ ReactDOM . render (
990+ < ErrorBoundary errorMessageRef = { errorMessageRef } >
991+ < div ref = { childRef } />
992+ < BrokenRender />
993+ </ ErrorBoundary > ,
994+ container ,
995+ ) ;
996+ expect ( container . textContent ) . toBe ( 'Caught an error: Hello.' ) ;
997+ expect ( log ) . toEqual ( [
998+ 'ErrorBoundary constructor' ,
999+ 'ErrorBoundary componentWillMount' ,
1000+ 'ErrorBoundary render success' ,
1001+ 'BrokenRender constructor' ,
1002+ 'BrokenRender componentWillMount' ,
1003+ 'BrokenRender render [!]' ,
1004+ // Handle error:
1005+ // Finish mounting with null children
1006+ 'ErrorBoundary componentDidMount' ,
1007+ // Handle the error
1008+ 'ErrorBoundary componentDidCatch' ,
1009+ // Render the error message
1010+ 'ErrorBoundary componentWillUpdate' ,
1011+ 'ErrorBoundary render error' ,
1012+ 'ErrorBoundary componentDidUpdate' ,
1013+ ] ) ;
1014+ expect ( errorMessageRef . value . toString ( ) ) . toEqual ( '[object HTMLDivElement]' ) ;
1015+
1016+ log . length = 0 ;
1017+ ReactDOM . unmountComponentAtNode ( container ) ;
1018+ expect ( log ) . toEqual ( [ 'ErrorBoundary componentWillUnmount' ] ) ;
1019+ expect ( errorMessageRef . value ) . toEqual ( null ) ;
1020+ } ) ;
1021+
9841022 it ( 'successfully mounts if no error occurs' , ( ) => {
9851023 const container = document . createElement ( 'div' ) ;
9861024 ReactDOM . render (
0 commit comments