refactor: remove unused code related to tooltip-v2 (#22304)

* refactor: remove unused code related to tooltip-v2

* test: redo & rewrite refs test
This commit is contained in:
Noblet Ouways
2025-09-24 02:49:29 +02:00
committed by GitHub
parent 3b72e183d8
commit 630b66f4cc
4 changed files with 13 additions and 53 deletions

View File

@@ -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<HTMLDivElement>()
const secondRef = ref<HTMLDivElement>()
composeRefs(firstRef, secondRef)(element)
expect(firstRef.value).toBe(element)
expect(secondRef.value).toBe(element)
})
})

View File

@@ -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.', () => {

View File

@@ -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<HTMLElement | undefined> | RefSetter)[]
) => {
export const composeRefs = (...refs: Ref<HTMLElement | undefined>[]) => {
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
})
}
}

View File

@@ -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<VNodeChildAtom | RawSlots>
export const flattedChildren = (