@@ -1160,4 +1160,174 @@ describe('reactElementToJSXString(ReactElement)', () => {
1160
1160
}
1161
1161
mount ( < App /> ) ;
1162
1162
} ) ;
1163
+
1164
+ it ( 'should use inferred function name as display name for `forwardRef` element' , ( ) => {
1165
+ const Tag = React . forwardRef ( function Tag ( { text } , ref ) {
1166
+ return < span ref = { ref } > { text } </ span > ;
1167
+ } ) ;
1168
+ expect ( reactElementToJSXString ( < Tag text = "some label" /> ) ) . toEqual (
1169
+ `<Tag text="some label" />`
1170
+ ) ;
1171
+ } ) ;
1172
+
1173
+ it ( 'should use `displayName` instead of inferred function name as display name for `forwardRef` element' , ( ) => {
1174
+ const Tag = React . forwardRef ( function Tag ( { text } , ref ) {
1175
+ return < span ref = { ref } > { text } </ span > ;
1176
+ } ) ;
1177
+ Tag . displayName = 'MyTag' ;
1178
+ expect ( reactElementToJSXString ( < Tag text = "some label" /> ) ) . toEqual (
1179
+ `<MyTag text="some label" />`
1180
+ ) ;
1181
+ } ) ;
1182
+
1183
+ it ( 'should use inferred function name as display name for `memo` element' , ( ) => {
1184
+ const Tag = React . memo ( function Tag ( { text } ) {
1185
+ return < span > { text } </ span > ;
1186
+ } ) ;
1187
+ expect ( reactElementToJSXString ( < Tag text = "some label" /> ) ) . toEqual (
1188
+ `<Tag text="some label" />`
1189
+ ) ;
1190
+ } ) ;
1191
+
1192
+ it ( 'should use `displayName` instead of inferred function name as display name for `memo` element' , ( ) => {
1193
+ const Tag = React . memo ( function Tag ( { text } ) {
1194
+ return < span > { text } </ span > ;
1195
+ } ) ;
1196
+ Tag . displayName = 'MyTag' ;
1197
+ expect ( reactElementToJSXString ( < Tag text = "some label" /> ) ) . toEqual (
1198
+ `<MyTag text="some label" />`
1199
+ ) ;
1200
+ } ) ;
1201
+
1202
+ it ( 'should use inferred function name as display name for a `forwardRef` wrapped in `memo`' , ( ) => {
1203
+ const Tag = React . memo (
1204
+ React . forwardRef ( function Tag ( { text } , ref ) {
1205
+ return < span ref = { ref } > { text } </ span > ;
1206
+ } )
1207
+ ) ;
1208
+ expect ( reactElementToJSXString ( < Tag text = "some label" /> ) ) . toEqual (
1209
+ `<Tag text="some label" />`
1210
+ ) ;
1211
+ } ) ;
1212
+
1213
+ it ( 'should use inferred function name as display name for a component wrapped in `memo` multiple times' , ( ) => {
1214
+ const Tag = React . memo (
1215
+ React . memo (
1216
+ React . memo ( function Tag ( { text } ) {
1217
+ return < span > { text } </ span > ;
1218
+ } )
1219
+ )
1220
+ ) ;
1221
+ expect ( reactElementToJSXString ( < Tag text = "some label" /> ) ) . toEqual (
1222
+ `<Tag text="some label" />`
1223
+ ) ;
1224
+ } ) ;
1225
+
1226
+ it ( 'should stringify `StrictMode` correctly' , ( ) => {
1227
+ const App = ( ) => null ;
1228
+
1229
+ expect (
1230
+ reactElementToJSXString (
1231
+ < React . StrictMode >
1232
+ < App />
1233
+ </ React . StrictMode >
1234
+ )
1235
+ ) . toEqual ( `<StrictMode>
1236
+ <App />
1237
+ </StrictMode>` ) ;
1238
+ } ) ;
1239
+
1240
+ it ( 'should stringify `Suspense` correctly' , ( ) => {
1241
+ const Spinner = ( ) => null ;
1242
+ const ProfilePage = ( ) => null ;
1243
+
1244
+ expect (
1245
+ reactElementToJSXString (
1246
+ < React . Suspense fallback = { < Spinner /> } >
1247
+ < ProfilePage />
1248
+ </ React . Suspense >
1249
+ )
1250
+ ) . toEqual ( `<Suspense fallback={<Spinner />}>
1251
+ <ProfilePage />
1252
+ </Suspense>` ) ;
1253
+ } ) ;
1254
+
1255
+ it ( 'should stringify `Profiler` correctly' , ( ) => {
1256
+ const Navigation = ( ) => null ;
1257
+
1258
+ expect (
1259
+ reactElementToJSXString (
1260
+ < React . Profiler id = "Navigation" onRender = { ( ) => { } } >
1261
+ < Navigation />
1262
+ </ React . Profiler >
1263
+ )
1264
+ ) . toEqual ( `<Profiler
1265
+ id="Navigation"
1266
+ onRender={function noRefCheck() {}}
1267
+ >
1268
+ <Navigation />
1269
+ </Profiler>` ) ;
1270
+ } ) ;
1271
+
1272
+ it ( 'should stringify `Contex.Provider` correctly' , ( ) => {
1273
+ const Ctx = React . createContext ( ) ;
1274
+ const App = ( ) => { } ;
1275
+
1276
+ expect (
1277
+ reactElementToJSXString (
1278
+ < Ctx . Provider value = { null } >
1279
+ < App />
1280
+ </ Ctx . Provider >
1281
+ )
1282
+ ) . toEqual ( `<Context.Provider value={null}>
1283
+ <App />
1284
+ </Context.Provider>` ) ;
1285
+ } ) ;
1286
+
1287
+ it ( 'should stringify `Contex.Provider` with `displayName` correctly' , ( ) => {
1288
+ const Ctx = React . createContext ( ) ;
1289
+ Ctx . displayName = 'MyCtx' ;
1290
+
1291
+ const App = ( ) => { } ;
1292
+
1293
+ expect (
1294
+ reactElementToJSXString (
1295
+ < Ctx . Provider value = { null } >
1296
+ < App />
1297
+ </ Ctx . Provider >
1298
+ )
1299
+ ) . toEqual ( `<MyCtx.Provider value={null}>
1300
+ <App />
1301
+ </MyCtx.Provider>` ) ;
1302
+ } ) ;
1303
+
1304
+ it ( 'should stringify `Contex.Consumer` correctly' , ( ) => {
1305
+ const Ctx = React . createContext ( ) ;
1306
+ const Button = ( ) => null ;
1307
+
1308
+ expect (
1309
+ reactElementToJSXString (
1310
+ < Ctx . Consumer > { theme => < Button theme = { theme } /> } </ Ctx . Consumer >
1311
+ )
1312
+ ) . toEqual ( `<Context.Consumer />` ) ;
1313
+ } ) ;
1314
+
1315
+ it ( 'should stringify `Contex.Consumer` with `displayName` correctly' , ( ) => {
1316
+ const Ctx = React . createContext ( ) ;
1317
+ Ctx . displayName = 'MyCtx' ;
1318
+
1319
+ const Button = ( ) => null ;
1320
+
1321
+ expect (
1322
+ reactElementToJSXString (
1323
+ < Ctx . Consumer > { theme => < Button theme = { theme } /> } </ Ctx . Consumer >
1324
+ )
1325
+ ) . toEqual ( `<MyCtx.Consumer />` ) ;
1326
+ } ) ;
1327
+
1328
+ it ( 'should stringify `lazy` component correctly' , ( ) => {
1329
+ const Lazy = React . lazy ( ( ) => Promise . resolve ( ( ) => { } ) ) ;
1330
+
1331
+ expect ( reactElementToJSXString ( < Lazy /> ) ) . toEqual ( `<Lazy />` ) ;
1332
+ } ) ;
1163
1333
} ) ;
0 commit comments