@@ -131,22 +131,22 @@ describe('reactiverefs', () => {
131
131
) ;
132
132
} ) ;
133
133
} ) . toErrorDev ( [
134
- 'Warning: Component "div" contains the string ref "resetDiv". ' +
135
- 'Support for string refs will be removed in a future major release. ' +
136
- 'We recommend using useRef() or createRef() instead. ' +
137
- 'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
138
- ' in div (at **)\n' +
139
- ' in TestRefsComponent (at **)' ,
140
- 'Warning: Component "span" contains the string ref "clickLog0". ' +
141
- 'Support for string refs will be removed in a future major release. ' +
142
- 'We recommend using useRef() or createRef() instead. ' +
143
- 'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
144
- ' in span (at **)\n' +
145
- ' in ClickCounter (at **)\n' +
134
+ 'Warning: Component "TestRefsComponent" contains the string ' +
135
+ 'ref "resetDiv". Support for string refs will be removed in a ' +
136
+ 'future major release. We recommend using useRef() or createRef() ' +
137
+ 'instead. Learn more about using refs safely ' +
138
+ 'here: https://reactjs.org/link/strict-mode-string-ref\n' +
146
139
' in div (at **)\n' +
147
- ' in GeneralContainerComponent (at **)\n' +
148
140
' in div (at **)\n' +
149
141
' in TestRefsComponent (at **)' ,
142
+ 'Warning: Component "ClickCounter" contains the string ' +
143
+ 'ref "clickLog0". Support for string refs will be removed in a ' +
144
+ 'future major release. We recommend using useRef() or createRef() ' +
145
+ 'instead. Learn more about using refs safely ' +
146
+ 'here: https://reactjs.org/link/strict-mode-string-ref\n' +
147
+ ' in div (at **)\n' +
148
+ ' in span (at **)\n' +
149
+ ' in ClickCounter (at **)' ,
150
150
] ) ;
151
151
152
152
expect ( testRefsComponent instanceof TestRefsComponent ) . toBe ( true ) ;
@@ -387,29 +387,29 @@ describe('ref swapping', () => {
387
387
'Support for string refs will be removed in a future major release. ' +
388
388
'We recommend using useRef() or createRef() instead. ' +
389
389
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
390
+ ' in div (at **)\n' +
390
391
' in A (at **)' ,
391
392
] ) ;
392
393
expect ( a . refs [ 1 ] . nodeName ) . toBe ( 'DIV' ) ;
393
394
} ) ;
394
395
395
- // @gate !disableStringRefs
396
396
it ( 'provides an error for invalid refs' , async ( ) => {
397
397
const container = document . createElement ( 'div' ) ;
398
398
const root = ReactDOMClient . createRoot ( container ) ;
399
399
await expect ( async ( ) => {
400
400
await act ( ( ) => {
401
401
root . render ( < div ref = { 10 } /> ) ;
402
402
} ) ;
403
- } ) . rejects . toThrow (
404
- 'Element ref was specified as a string (10) but no owner was set.' ,
405
- ) ;
403
+ // TODO: This throws an AggregateError. Need to update test infra to
404
+ // support matching against AggregateError.
405
+ } ) . rejects . toThrow ( ) ;
406
406
await expect ( async ( ) => {
407
407
await act ( ( ) => {
408
408
root . render ( < div ref = { true } /> ) ;
409
409
} ) ;
410
- } ) . rejects . toThrow (
411
- 'Element ref was specified as a string (true) but no owner was set.' ,
412
- ) ;
410
+ // TODO: This throws an AggregateError. Need to update test infra to
411
+ // support matching against AggregateError.
412
+ } ) . rejects . toThrow ( ) ;
413
413
await expect ( async ( ) => {
414
414
await act ( ( ) => {
415
415
root . render ( < div ref = { Symbol ( 'foo' ) } /> ) ;
@@ -546,7 +546,6 @@ describe('creating element with string ref in constructor', () => {
546
546
}
547
547
}
548
548
549
- // @gate !disableStringRefs
550
549
it ( 'throws an error' , async ( ) => {
551
550
await expect ( async function ( ) {
552
551
const container = document . createElement ( 'div' ) ;
@@ -555,14 +554,9 @@ describe('creating element with string ref in constructor', () => {
555
554
await act ( ( ) => {
556
555
root . render ( < RefTest /> ) ;
557
556
} ) ;
558
- } ) . rejects . toThrowError (
559
- 'Element ref was specified as a string (p) but no owner was set. This could happen for one of' +
560
- ' the following reasons:\n' +
561
- '1. You may be adding a ref to a function component\n' +
562
- "2. You may be adding a ref to a component that was not created inside a component's render method\n" +
563
- '3. You have multiple copies of React loaded\n' +
564
- 'See https://reactjs.org/link/refs-must-have-owner for more information.' ,
565
- ) ;
557
+ // TODO: This throws an AggregateError. Need to update test infra to
558
+ // support matching against AggregateError.
559
+ } ) . rejects . toThrowError ( ) ;
566
560
} ) ;
567
561
} ) ;
568
562
@@ -616,10 +610,11 @@ describe('strings refs across renderers', () => {
616
610
) ;
617
611
} ) ;
618
612
} ) . toErrorDev ( [
619
- 'Warning: Component "Indirection " contains the string ref "child1". ' +
613
+ 'Warning: Component "Parent " contains the string ref "child1". ' +
620
614
'Support for string refs will be removed in a future major release. ' +
621
615
'We recommend using useRef() or createRef() instead. ' +
622
616
'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref\n' +
617
+ ' in div (at **)\n' +
623
618
' in Indirection (at **)\n' +
624
619
' in Parent (at **)' ,
625
620
] ) ;
@@ -628,20 +623,10 @@ describe('strings refs across renderers', () => {
628
623
expect ( inst . refs . child1 . tagName ) . toBe ( 'DIV' ) ;
629
624
expect ( inst . refs . child1 ) . toBe ( div1 . firstChild ) ;
630
625
631
- await expect ( async ( ) => {
632
- // Now both refs should be rendered.
633
- await act ( ( ) => {
634
- root . render ( < Parent /> ) ;
635
- } ) ;
636
- } ) . toErrorDev (
637
- [
638
- 'Warning: Component "Root" contains the string ref "child2". ' +
639
- 'Support for string refs will be removed in a future major release. ' +
640
- 'We recommend using useRef() or createRef() instead. ' +
641
- 'Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref' ,
642
- ] ,
643
- { withoutStack : true } ,
644
- ) ;
626
+ // Now both refs should be rendered.
627
+ await act ( ( ) => {
628
+ root . render ( < Parent /> ) ;
629
+ } ) ;
645
630
expect ( inst . refs . child1 . tagName ) . toBe ( 'DIV' ) ;
646
631
expect ( inst . refs . child1 ) . toBe ( div1 . firstChild ) ;
647
632
expect ( inst . refs . child2 . tagName ) . toBe ( 'DIV' ) ;
0 commit comments