@@ -937,7 +937,7 @@ describe('ReactErrorBoundaries', () => {
937
937
expect ( log ) . toEqual ( [ 'ErrorBoundary componentWillUnmount' ] ) ;
938
938
} ) ;
939
939
940
- it ( 'resets refs if mounting aborts' , ( ) => {
940
+ it ( 'resets callback refs if mounting aborts' , ( ) => {
941
941
function childRef ( x ) {
942
942
log . push ( 'Child ref is set to ' + x ) ;
943
943
}
@@ -981,6 +981,44 @@ describe('ReactErrorBoundaries', () => {
981
981
] ) ;
982
982
} ) ;
983
983
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
+
984
1022
it ( 'successfully mounts if no error occurs' , ( ) => {
985
1023
const container = document . createElement ( 'div' ) ;
986
1024
ReactDOM . render (
0 commit comments