@@ -1087,4 +1087,67 @@ describe('reactElementToJSXString(ReactElement)', () => {
10871087 )
10881088 ) . toEqual ( `<div render={<><div /><div /></>} />` ) ;
10891089 } ) ;
1090+
1091+ it ( 'should not cause recursive loop when prop object contains an element' , ( ) => {
1092+ const FunctionComp = ( ) => {
1093+ return < span > hello func</ span > ;
1094+ } ;
1095+
1096+ class ClassComp extends React . Component {
1097+ render ( ) {
1098+ return < span > hello class</ span > ;
1099+ }
1100+ }
1101+
1102+ class MainComp extends React . Component {
1103+ render ( ) {
1104+ return < div { ...this . props } /> ;
1105+ }
1106+ }
1107+
1108+ // Simple test, one level of nesting.
1109+ const elementToTest = (
1110+ < MainComp
1111+ title = { { comp : < FunctionComp /> } }
1112+ subtitle = { { anotherComp : < ClassComp /> } }
1113+ />
1114+ ) ;
1115+
1116+ const jsxString = reactElementToJSXString ( elementToTest ) ;
1117+ expect ( jsxString ) . toBe ( `<MainComp
1118+ subtitle={{
1119+ anotherComp: <ClassComp />
1120+ }}
1121+ title={{
1122+ comp: <FunctionComp />
1123+ }}
1124+ />` ) ;
1125+
1126+ // Deep nested component inside props.
1127+ const nestedElementToTest = (
1128+ < MainComp
1129+ title = { {
1130+ comp : (
1131+ < MainComp
1132+ some = { {
1133+ content : (
1134+ < ClassComp other = { { nested : { comp : < FunctionComp /> } } } />
1135+ ) ,
1136+ } }
1137+ />
1138+ ) ,
1139+ } }
1140+ subtitle = { { anotherComp : < ClassComp /> } }
1141+ />
1142+ ) ;
1143+ const nestedJsxString = reactElementToJSXString ( nestedElementToTest ) ;
1144+ expect ( nestedJsxString ) . toBe ( `<MainComp
1145+ subtitle={{
1146+ anotherComp: <ClassComp />
1147+ }}
1148+ title={{
1149+ comp: <MainComp some={{content: <ClassComp other={{nested: {comp: <FunctionComp />}}} />}} />
1150+ }}
1151+ />` ) ;
1152+ } ) ;
10901153} ) ;
0 commit comments