Skip to content

Commit 4de5b11

Browse files
committed
test: fix cloneVNode ref tests
1 parent be946ea commit 4de5b11

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

packages/runtime-core/__tests__/vnode.spec.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,37 +230,56 @@ describe('vnode', () => {
230230

231231
setCurrentRenderingInstance(mockInstance1)
232232
const original = createVNode('div', { ref: 'foo' })
233-
expect(original.ref).toEqual([mockInstance1, 'foo'])
233+
expect(original.ref).toStrictEqual({ i: mockInstance1, r: 'foo' })
234234

235235
// clone and preserve original ref
236236
const cloned1 = cloneVNode(original)
237-
expect(cloned1.ref).toEqual([mockInstance1, 'foo'])
237+
expect(cloned1.ref).toStrictEqual({ i: mockInstance1, r: 'foo' })
238238

239239
// cloning with new ref, but with same context instance
240240
const cloned2 = cloneVNode(original, { ref: 'bar' })
241-
expect(cloned2.ref).toEqual([mockInstance1, 'bar'])
241+
expect(cloned2.ref).toStrictEqual({ i: mockInstance1, r: 'bar' })
242242

243243
// cloning and adding ref to original that has no ref
244244
const original2 = createVNode('div')
245245
const cloned3 = cloneVNode(original2, { ref: 'bar' })
246-
expect(cloned3.ref).toEqual([mockInstance1, 'bar'])
246+
expect(cloned3.ref).toStrictEqual({ i: mockInstance1, r: 'bar' })
247247

248248
// cloning with different context instance
249249
setCurrentRenderingInstance(mockInstance2)
250250

251251
// clone and preserve original ref
252252
const cloned4 = cloneVNode(original)
253253
// #1311 should preserve original context instance!
254-
expect(cloned4.ref).toEqual([mockInstance1, 'foo'])
254+
expect(cloned4.ref).toStrictEqual({ i: mockInstance1, r: 'foo' })
255255

256256
// cloning with new ref, but with same context instance
257257
const cloned5 = cloneVNode(original, { ref: 'bar' })
258258
// 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' })
260260

261261
// cloning and adding ref to original that has no ref
262262
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+
])
264283

265284
setCurrentRenderingInstance(null)
266285
})

0 commit comments

Comments
 (0)