@@ -12,7 +12,7 @@ import {
12
12
} from '../src/vnode'
13
13
import { Data } from '../src/component'
14
14
import { ShapeFlags , PatchFlags } from '@vue/shared'
15
- import { h , reactive , isReactive , setBlockTracking } from '../src'
15
+ import { h , reactive , isReactive , setBlockTracking , ref } from '../src'
16
16
import { createApp , nodeOps , serializeInner } from '@vue/runtime-test'
17
17
import { setCurrentRenderingInstance } from '../src/componentRenderContext'
18
18
@@ -236,37 +236,60 @@ describe('vnode', () => {
236
236
237
237
setCurrentRenderingInstance ( mockInstance1 )
238
238
const original = createVNode ( 'div' , { ref : 'foo' } )
239
- expect ( original . ref ) . toStrictEqual ( { i : mockInstance1 , r : 'foo' } )
239
+ expect ( original . ref ) . toMatchObject ( {
240
+ i : mockInstance1 ,
241
+ r : 'foo' ,
242
+ f : false
243
+ } )
240
244
241
245
// clone and preserve original ref
242
246
const cloned1 = cloneVNode ( original )
243
- expect ( cloned1 . ref ) . toStrictEqual ( { i : mockInstance1 , r : 'foo' } )
247
+ expect ( cloned1 . ref ) . toMatchObject ( { i : mockInstance1 , r : 'foo' , f : false } )
244
248
245
249
// cloning with new ref, but with same context instance
246
250
const cloned2 = cloneVNode ( original , { ref : 'bar' } )
247
- expect ( cloned2 . ref ) . toStrictEqual ( { i : mockInstance1 , r : 'bar' } )
251
+ expect ( cloned2 . ref ) . toMatchObject ( { i : mockInstance1 , r : 'bar' , f : false } )
248
252
249
253
// cloning and adding ref to original that has no ref
250
254
const original2 = createVNode ( 'div' )
251
255
const cloned3 = cloneVNode ( original2 , { ref : 'bar' } )
252
- expect ( cloned3 . ref ) . toStrictEqual ( { i : mockInstance1 , r : 'bar' } )
256
+ expect ( cloned3 . ref ) . toMatchObject ( { i : mockInstance1 , r : 'bar' , f : false } )
253
257
254
258
// cloning with different context instance
255
259
setCurrentRenderingInstance ( mockInstance2 )
256
260
257
261
// clone and preserve original ref
258
262
const cloned4 = cloneVNode ( original )
259
263
// #1311 should preserve original context instance!
260
- expect ( cloned4 . ref ) . toStrictEqual ( { i : mockInstance1 , r : 'foo' } )
264
+ expect ( cloned4 . ref ) . toMatchObject ( { i : mockInstance1 , r : 'foo' , f : false } )
261
265
262
266
// cloning with new ref, but with same context instance
263
267
const cloned5 = cloneVNode ( original , { ref : 'bar' } )
264
268
// new ref should use current context instance and overwrite original
265
- expect ( cloned5 . ref ) . toStrictEqual ( { i : mockInstance2 , r : 'bar' } )
269
+ expect ( cloned5 . ref ) . toMatchObject ( { i : mockInstance2 , r : 'bar' , f : false } )
266
270
267
271
// cloning and adding ref to original that has no ref
268
272
const cloned6 = cloneVNode ( original2 , { ref : 'bar' } )
269
- expect ( cloned6 . ref ) . toStrictEqual ( { i : mockInstance2 , r : 'bar' } )
273
+ expect ( cloned6 . ref ) . toMatchObject ( { i : mockInstance2 , r : 'bar' , f : false } )
274
+
275
+ const original3 = createVNode ( 'div' , { ref : 'foo' , ref_for : true } )
276
+ expect ( original3 . ref ) . toMatchObject ( {
277
+ i : mockInstance2 ,
278
+ r : 'foo' ,
279
+ f : true
280
+ } )
281
+ const cloned7 = cloneVNode ( original3 , { ref : 'bar' , ref_for : true } )
282
+ expect ( cloned7 . ref ) . toMatchObject ( { i : mockInstance2 , r : 'bar' , f : true } )
283
+
284
+ const r = ref ( )
285
+ const original4 = createVNode ( 'div' , { ref : r , ref_key : 'foo' } )
286
+ expect ( original4 . ref ) . toMatchObject ( {
287
+ i : mockInstance2 ,
288
+ r,
289
+ k : 'foo'
290
+ } )
291
+ const cloned8 = cloneVNode ( original4 )
292
+ expect ( cloned8 . ref ) . toMatchObject ( { i : mockInstance2 , r, k : 'foo' } )
270
293
271
294
setCurrentRenderingInstance ( null )
272
295
} )
@@ -277,14 +300,14 @@ describe('vnode', () => {
277
300
278
301
setCurrentRenderingInstance ( mockInstance1 )
279
302
const original = createVNode ( 'div' , { ref : 'foo' } )
280
- expect ( original . ref ) . toStrictEqual ( { i : mockInstance1 , r : 'foo' } )
303
+ expect ( original . ref ) . toMatchObject ( { i : mockInstance1 , r : 'foo' , f : false } )
281
304
282
305
// clone and preserve original ref
283
306
setCurrentRenderingInstance ( mockInstance2 )
284
307
const cloned1 = cloneVNode ( original , { ref : 'bar' } , true )
285
- expect ( cloned1 . ref ) . toStrictEqual ( [
286
- { i : mockInstance1 , r : 'foo' } ,
287
- { i : mockInstance2 , r : 'bar' }
308
+ expect ( cloned1 . ref ) . toMatchObject ( [
309
+ { i : mockInstance1 , r : 'foo' , f : false } ,
310
+ { i : mockInstance2 , r : 'bar' , f : false }
288
311
] )
289
312
290
313
setCurrentRenderingInstance ( null )
0 commit comments