From 630b66f4cc71be9628d680b0aafee3d1835c6504 Mon Sep 17 00:00:00 2001 From: Noblet Ouways <91417411+Dsaquel@users.noreply.github.com> Date: Wed, 24 Sep 2025 02:49:29 +0200 Subject: [PATCH] refactor: remove unused code related to tooltip-v2 (#22304) * refactor: remove unused code related to tooltip-v2 * test: redo & rewrite refs test --- packages/utils/__tests__/vue/refs.test.ts | 15 +++++++++------ packages/utils/__tests__/vue/vnode.test.ts | 21 +-------------------- packages/utils/vue/refs.ts | 16 ++-------------- packages/utils/vue/vnode.ts | 14 +------------- 4 files changed, 13 insertions(+), 53 deletions(-) diff --git a/packages/utils/__tests__/vue/refs.test.ts b/packages/utils/__tests__/vue/refs.test.ts index a723bbdff7..684ff6a0ba 100644 --- a/packages/utils/__tests__/vue/refs.test.ts +++ b/packages/utils/__tests__/vue/refs.test.ts @@ -1,11 +1,14 @@ -import { describe, expect, it, vi } from 'vitest' +import { ref } from 'vue' +import { describe, expect, it } from 'vitest' import { composeRefs } from '../..' describe('composeRefs', () => { - it('ref setter should be called', () => { - const refSetter = vi.fn() - const fn = composeRefs(refSetter) - fn(null) - expect(refSetter).toHaveBeenCalled() + it('should assign correctly the element to the given refs', () => { + const element = document.createElement('div') + const firstRef = ref() + const secondRef = ref() + composeRefs(firstRef, secondRef)(element) + expect(firstRef.value).toBe(element) + expect(secondRef.value).toBe(element) }) }) diff --git a/packages/utils/__tests__/vue/vnode.test.ts b/packages/utils/__tests__/vue/vnode.test.ts index 47a5a4baa5..ded71500f2 100644 --- a/packages/utils/__tests__/vue/vnode.test.ts +++ b/packages/utils/__tests__/vue/vnode.test.ts @@ -1,24 +1,5 @@ import { describe, expect, it } from 'vitest' -import { ensureOnlyChild, flattedChildren } from '../..' - -describe('ensureOnlyChild', () => { - it('it should throw an error if input is not an array or undefined', () => { - expect(() => { - ensureOnlyChild('not an array' as any) - }).toThrow('expect to receive a single Vue element child') - }) - - it('it should throw an error if input array has more than one element', () => { - expect(() => { - ensureOnlyChild([1, 2]) - }).toThrow('expect to receive a single Vue element child') - }) - - it('it should return the only child if input is an array with one element', () => { - const child = { type: 'div' } - expect(ensureOnlyChild([child as any])).toEqual(child) - }) -}) +import { flattedChildren } from '../..' describe('flattedChildren', () => { it('Component vnode has no child nodes.', () => { diff --git a/packages/utils/vue/refs.ts b/packages/utils/vue/refs.ts index d1cc36a0d2..eae59f571c 100644 --- a/packages/utils/vue/refs.ts +++ b/packages/utils/vue/refs.ts @@ -1,21 +1,9 @@ -import { isFunction } from '../types' - import type { ComponentPublicInstance, Ref } from 'vue' -export type RefSetter = ( - el: Element | ComponentPublicInstance | undefined -) => void - -export const composeRefs = ( - ...refs: (Ref | RefSetter)[] -) => { +export const composeRefs = (...refs: Ref[]) => { return (el: Element | ComponentPublicInstance | null) => { refs.forEach((ref) => { - if (isFunction(ref)) { - ref(el as Element | ComponentPublicInstance) - } else { - ref.value = el as HTMLElement | undefined - } + ref.value = el as HTMLElement | undefined }) } } diff --git a/packages/utils/vue/vnode.ts b/packages/utils/vue/vnode.ts index c478f79405..337227c164 100644 --- a/packages/utils/vue/vnode.ts +++ b/packages/utils/vue/vnode.ts @@ -12,12 +12,7 @@ import { isArray } from '../types' import { hasOwn } from '../objects' import { debugWarn } from '../error' -import type { - VNode, - VNodeArrayChildren, - VNodeChild, - VNodeNormalizedChildren, -} from 'vue' +import type { VNode, VNodeChild, VNodeNormalizedChildren } from 'vue' const SCOPE = 'utils/vue/vnode' @@ -139,13 +134,6 @@ export const getNormalizedProps = (node: VNode) => { return props } -export const ensureOnlyChild = (children: VNodeArrayChildren | undefined) => { - if (!isArray(children) || children.length > 1) { - throw new Error('expect to receive a single Vue element child') - } - return children[0] -} - export type FlattenVNodes = Array export const flattedChildren = (