Files
element-plus/packages/utils/__tests__/vue/vnode.test.ts
wzc520pyfm 98ce640684 test(utils): [vue] add icon,install,vnode and global-node test (#16216)
* test(utils): [vue] add icon,install,vnode and global-node test

* test(utils): [global-node] remove repeat code of useless
2024-04-30 10:37:27 +08:00

22 lines
722 B
TypeScript

import { describe, expect, it } from 'vitest'
import { ensureOnlyChild } 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)
})
})