@@ -232,28 +232,25 @@ describe('ReactFunctionComponent', () => {
232
232
' in ParentUsingStringRef (at **)' ,
233
233
) ;
234
234
235
+ // No additional warnings should be logged
235
236
const container = document . createElement ( 'div' ) ;
236
237
const root = ReactDOMClient . createRoot ( container ) ;
237
238
await act ( ( ) => {
238
239
root . render ( < ParentUsingStringRef /> ) ;
239
240
} ) ;
240
241
} ) ;
241
242
242
- it ( 'should warn when given a function ref' , async ( ) => {
243
+ it ( 'should warn when given a function ref and ignore them ' , async ( ) => {
243
244
function Indirection ( props ) {
244
245
return < div > { props . children } </ div > ;
245
246
}
246
247
248
+ const ref = jest . fn ( ) ;
247
249
class ParentUsingFunctionRef extends React . Component {
248
250
render ( ) {
249
251
return (
250
252
< Indirection >
251
- < FunctionComponent
252
- name = "A"
253
- ref = { arg => {
254
- expect ( arg ) . toBe ( null ) ;
255
- } }
256
- />
253
+ < FunctionComponent name = "A" ref = { ref } />
257
254
</ Indirection >
258
255
) ;
259
256
}
@@ -276,7 +273,9 @@ describe('ReactFunctionComponent', () => {
276
273
' in Indirection (at **)\n' +
277
274
' in ParentUsingFunctionRef (at **)' ,
278
275
) ;
276
+ expect ( ref ) . not . toHaveBeenCalled ( ) ;
279
277
278
+ // No additional warnings should be logged
280
279
const container = document . createElement ( 'div' ) ;
281
280
const root = ReactDOMClient . createRoot ( container ) ;
282
281
await act ( ( ) => {
@@ -306,9 +305,9 @@ describe('ReactFunctionComponent', () => {
306
305
} ) . toErrorDev ( 'Warning: Function components cannot be given refs.' ) ;
307
306
// Should be deduped (offending element is on the same line):
308
307
instance1 . forceUpdate ( ) ;
308
+ // Should also be deduped (offending element is on the same line):
309
309
let container = document . createElement ( 'div' ) ;
310
310
let root = ReactDOMClient . createRoot ( container ) ;
311
-
312
311
await act ( ( ) => {
313
312
root . render ( < AnonymousParentUsingJSX /> ) ;
314
313
} ) ;
@@ -335,6 +334,7 @@ describe('ReactFunctionComponent', () => {
335
334
} ) . toErrorDev ( 'Warning: Function components cannot be given refs.' ) ;
336
335
// Should be deduped (same internal instance, no additional warnings)
337
336
instance2 . forceUpdate ( ) ;
337
+ // Could not be differentiated (since owner is anonymous and no source location)
338
338
container = document . createElement ( 'div' ) ;
339
339
root = ReactDOMClient . createRoot ( container ) ;
340
340
await act ( ( ) => {
@@ -362,6 +362,7 @@ describe('ReactFunctionComponent', () => {
362
362
} ) . toErrorDev ( 'Warning: Function components cannot be given refs.' ) ;
363
363
// Should be deduped (same owner name, no additional warnings):
364
364
instance3 . forceUpdate ( ) ;
365
+ // Should also be deduped (same owner name, no additional warnings):
365
366
container = document . createElement ( 'div' ) ;
366
367
root = ReactDOMClient . createRoot ( container ) ;
367
368
await act ( ( ) => {
0 commit comments