@@ -19,6 +19,7 @@ import {
19
19
nextTick ,
20
20
reactive ,
21
21
ref ,
22
+ shallowRef ,
22
23
useTemplateRef ,
23
24
watchEffect ,
24
25
} from '@vue/runtime-dom'
@@ -208,8 +209,8 @@ describe('api: template ref', () => {
208
209
const { render } = define ( {
209
210
setup ( ) {
210
211
return {
211
- foo : fooEl ,
212
- bar : barEl ,
212
+ foo : shallowRef ( fooEl ) ,
213
+ bar : shallowRef ( barEl ) ,
213
214
}
214
215
} ,
215
216
render ( ) {
@@ -251,6 +252,7 @@ describe('api: template ref', () => {
251
252
} )
252
253
const { host } = render ( )
253
254
expect ( state . refKey ) . toBe ( host . children [ 0 ] )
255
+ expect ( 'Template ref "refKey" used on a non-ref value' ) . toHaveBeenWarned ( )
254
256
} )
255
257
256
258
test ( 'multiple root refs' , ( ) => {
@@ -713,6 +715,26 @@ describe('api: template ref', () => {
713
715
expect ( html ( ) ) . toBe ( '<div>changed</div><!--dynamic-component-->' )
714
716
} )
715
717
718
+ test ( 'should not attempt to set when variable name is same as key' , ( ) => {
719
+ let tRef : ShallowRef
720
+ const key = 'refKey'
721
+ define ( {
722
+ setup ( ) {
723
+ tRef = useTemplateRef ( '_' )
724
+ return {
725
+ [ key ] : tRef ,
726
+ }
727
+ } ,
728
+ render ( ) {
729
+ const n0 = template ( '<div></div>' ) ( ) as Element
730
+ createTemplateRefSetter ( ) ( n0 , key )
731
+ return n0
732
+ } ,
733
+ } ) . render ( )
734
+ expect ( 'target is readonly' ) . not . toHaveBeenWarned ( )
735
+ expect ( tRef ! . value ) . toBe ( null )
736
+ } )
737
+
716
738
// TODO: can not reproduce in Vapor
717
739
// // #2078
718
740
// test('handling multiple merged refs', async () => {
0 commit comments