@@ -232,28 +232,25 @@ describe('ReactFunctionComponent', () => {
232232 ' in ParentUsingStringRef (at **)' ,
233233 ) ;
234234
235+ // No additional warnings should be logged
235236 const container = document . createElement ( 'div' ) ;
236237 const root = ReactDOMClient . createRoot ( container ) ;
237238 await act ( ( ) => {
238239 root . render ( < ParentUsingStringRef /> ) ;
239240 } ) ;
240241 } ) ;
241242
242- it ( 'should warn when given a function ref' , async ( ) => {
243+ it ( 'should warn when given a function ref and ignore them ' , async ( ) => {
243244 function Indirection ( props ) {
244245 return < div > { props . children } </ div > ;
245246 }
246247
248+ const ref = jest . fn ( ) ;
247249 class ParentUsingFunctionRef extends React . Component {
248250 render ( ) {
249251 return (
250252 < Indirection >
251- < FunctionComponent
252- name = "A"
253- ref = { arg => {
254- expect ( arg ) . toBe ( null ) ;
255- } }
256- />
253+ < FunctionComponent name = "A" ref = { ref } />
257254 </ Indirection >
258255 ) ;
259256 }
@@ -276,7 +273,9 @@ describe('ReactFunctionComponent', () => {
276273 ' in Indirection (at **)\n' +
277274 ' in ParentUsingFunctionRef (at **)' ,
278275 ) ;
276+ expect ( ref ) . not . toHaveBeenCalled ( ) ;
279277
278+ // No additional warnings should be logged
280279 const container = document . createElement ( 'div' ) ;
281280 const root = ReactDOMClient . createRoot ( container ) ;
282281 await act ( ( ) => {
@@ -306,9 +305,9 @@ describe('ReactFunctionComponent', () => {
306305 } ) . toErrorDev ( 'Warning: Function components cannot be given refs.' ) ;
307306 // Should be deduped (offending element is on the same line):
308307 instance1 . forceUpdate ( ) ;
308+ // Should also be deduped (offending element is on the same line):
309309 let container = document . createElement ( 'div' ) ;
310310 let root = ReactDOMClient . createRoot ( container ) ;
311-
312311 await act ( ( ) => {
313312 root . render ( < AnonymousParentUsingJSX /> ) ;
314313 } ) ;
@@ -335,6 +334,7 @@ describe('ReactFunctionComponent', () => {
335334 } ) . toErrorDev ( 'Warning: Function components cannot be given refs.' ) ;
336335 // Should be deduped (same internal instance, no additional warnings)
337336 instance2 . forceUpdate ( ) ;
337+ // Could not be differentiated (since owner is anonymous and no source location)
338338 container = document . createElement ( 'div' ) ;
339339 root = ReactDOMClient . createRoot ( container ) ;
340340 await act ( ( ) => {
@@ -362,6 +362,7 @@ describe('ReactFunctionComponent', () => {
362362 } ) . toErrorDev ( 'Warning: Function components cannot be given refs.' ) ;
363363 // Should be deduped (same owner name, no additional warnings):
364364 instance3 . forceUpdate ( ) ;
365+ // Should also be deduped (same owner name, no additional warnings):
365366 container = document . createElement ( 'div' ) ;
366367 root = ReactDOMClient . createRoot ( container ) ;
367368 await act ( ( ) => {
0 commit comments