@@ -230,37 +230,56 @@ describe('vnode', () => {
230
230
231
231
setCurrentRenderingInstance ( mockInstance1 )
232
232
const original = createVNode ( 'div' , { ref : 'foo' } )
233
- expect ( original . ref ) . toEqual ( [ mockInstance1 , 'foo' ] )
233
+ expect ( original . ref ) . toStrictEqual ( { i : mockInstance1 , r : 'foo' } )
234
234
235
235
// clone and preserve original ref
236
236
const cloned1 = cloneVNode ( original )
237
- expect ( cloned1 . ref ) . toEqual ( [ mockInstance1 , 'foo' ] )
237
+ expect ( cloned1 . ref ) . toStrictEqual ( { i : mockInstance1 , r : 'foo' } )
238
238
239
239
// cloning with new ref, but with same context instance
240
240
const cloned2 = cloneVNode ( original , { ref : 'bar' } )
241
- expect ( cloned2 . ref ) . toEqual ( [ mockInstance1 , 'bar' ] )
241
+ expect ( cloned2 . ref ) . toStrictEqual ( { i : mockInstance1 , r : 'bar' } )
242
242
243
243
// cloning and adding ref to original that has no ref
244
244
const original2 = createVNode ( 'div' )
245
245
const cloned3 = cloneVNode ( original2 , { ref : 'bar' } )
246
- expect ( cloned3 . ref ) . toEqual ( [ mockInstance1 , 'bar' ] )
246
+ expect ( cloned3 . ref ) . toStrictEqual ( { i : mockInstance1 , r : 'bar' } )
247
247
248
248
// cloning with different context instance
249
249
setCurrentRenderingInstance ( mockInstance2 )
250
250
251
251
// clone and preserve original ref
252
252
const cloned4 = cloneVNode ( original )
253
253
// #1311 should preserve original context instance!
254
- expect ( cloned4 . ref ) . toEqual ( [ mockInstance1 , 'foo' ] )
254
+ expect ( cloned4 . ref ) . toStrictEqual ( { i : mockInstance1 , r : 'foo' } )
255
255
256
256
// cloning with new ref, but with same context instance
257
257
const cloned5 = cloneVNode ( original , { ref : 'bar' } )
258
258
// new ref should use current context instance and overwrite original
259
- expect ( cloned5 . ref ) . toEqual ( [ mockInstance2 , 'bar' ] )
259
+ expect ( cloned5 . ref ) . toStrictEqual ( { i : mockInstance2 , r : 'bar' } )
260
260
261
261
// cloning and adding ref to original that has no ref
262
262
const cloned6 = cloneVNode ( original2 , { ref : 'bar' } )
263
- expect ( cloned6 . ref ) . toEqual ( [ mockInstance2 , 'bar' ] )
263
+ expect ( cloned6 . ref ) . toStrictEqual ( { i : mockInstance2 , r : 'bar' } )
264
+
265
+ setCurrentRenderingInstance ( null )
266
+ } )
267
+
268
+ test ( 'cloneVNode ref merging' , ( ) => {
269
+ const mockInstance1 = { } as any
270
+ const mockInstance2 = { } as any
271
+
272
+ setCurrentRenderingInstance ( mockInstance1 )
273
+ const original = createVNode ( 'div' , { ref : 'foo' } )
274
+ expect ( original . ref ) . toStrictEqual ( { i : mockInstance1 , r : 'foo' } )
275
+
276
+ // clone and preserve original ref
277
+ setCurrentRenderingInstance ( mockInstance2 )
278
+ const cloned1 = cloneVNode ( original , { ref : 'bar' } , true )
279
+ expect ( cloned1 . ref ) . toStrictEqual ( [
280
+ { i : mockInstance1 , r : 'foo' } ,
281
+ { i : mockInstance2 , r : 'bar' }
282
+ ] )
264
283
265
284
setCurrentRenderingInstance ( null )
266
285
} )
0 commit comments