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