mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
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:
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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.', () => {
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 = (
|
||||
|
||||
Reference in New Issue
Block a user