@@ -69,4 +69,55 @@ describe('ReactDeprecationWarnings', () => {
69
69
'\n in Component (at **)' ,
70
70
) ;
71
71
} ) ;
72
+
73
+ it ( 'should not warn when owner and self are the same for string refs' , ( ) => {
74
+ class RefComponent extends React . Component {
75
+ render ( ) {
76
+ return null ;
77
+ }
78
+ }
79
+ class Component extends React . Component {
80
+
81
+ render ( ) {
82
+ return < RefComponent ref = "refComponent" __self = { this } /> ;
83
+ }
84
+ }
85
+
86
+ ReactNoop . render ( < Component /> ) ;
87
+ expect ( ( ) => expect ( Scheduler ) . toFlushWithoutYielding ( ) ) . toErrorDev ( [
88
+ 'Warning: Component "Component" contains the string ref "refComponent". ' +
89
+ 'Support for string refs will be removed in a future major release. ' +
90
+ 'We recommend using useRef() or createRef() instead. ' +
91
+ 'Learn more about using refs safely here: ' +
92
+ 'https://fb.me/react-strict-mode-string-ref' +
93
+ '\n in Component (at **)' ,
94
+ ] ) ;
95
+ } )
96
+
97
+ it ( 'should warn when owner and self are different for string refs' , ( ) => {
98
+ class RefComponent extends React . Component {
99
+ render ( ) {
100
+ return null ;
101
+ }
102
+ }
103
+ class Component extends React . Component {
104
+
105
+ render ( ) {
106
+ return < RefComponent ref = "refComponent" __self = { { } } /> ;
107
+ }
108
+ }
109
+
110
+ ReactNoop . render ( < Component /> ) ;
111
+ expect ( ( ) => expect ( Scheduler ) . toFlushWithoutYielding ( ) ) . toErrorDev ( [
112
+ 'Warning: Owner and self do not match for the string ref "refComponent". Support for ' +
113
+ 'string refs will be removed in a future major release, and refs ' +
114
+ 'where owner and self are different cannot be safely codemoded. ' +
115
+ 'We recommend fixing these by hand by using useRef() or createRef() ' +
116
+ 'instead. Learn more about using refs safely here: ' +
117
+ 'https://fb.me/react-strict-mode-string-ref' +
118
+ '\n in Component (at **)' ,
119
+ ] ) ;
120
+
121
+ } )
122
+
72
123
} ) ;
0 commit comments