test(utils): [vue] add refs, size and validator test (#16201)

This commit is contained in:
wzc520pyfm 2024-03-23 09:43:03 +08:00 committed by GitHub
parent 2ae51ddb35
commit 223d0da28a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,11 @@
import { describe, expect, it, vi } 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()
})
})

View File

@ -0,0 +1,19 @@
import { describe, expect, it } from 'vitest'
import { getComponentSize } from '../..'
describe('vue size', () => {
it('default value', () => {
const value1 = getComponentSize()
const value2 = getComponentSize('default')
expect(value1).toBe(32)
expect(value2).toBe(32)
})
it('small value', () => {
const value = getComponentSize('small')
expect(value).toBe(24)
})
it('large value', () => {
const value = getComponentSize('large')
expect(value).toBe(40)
})
})

View File

@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest'
import { isValidComponentSize, isValidDatePickType } from '../..'
describe('validator', () => {
it('isValidComponentSize', () => {
expect(isValidComponentSize('')).toBe(true)
expect(isValidComponentSize('default')).toBe(true)
expect(isValidComponentSize('small')).toBe(true)
expect(isValidComponentSize('large')).toBe(true)
expect(isValidComponentSize('unknown')).toBe(false)
})
it('isValidDatePickType', () => {
expect(isValidDatePickType('year')).toBe(true)
expect(isValidDatePickType('years')).toBe(true)
expect(isValidDatePickType('month')).toBe(true)
expect(isValidDatePickType('date')).toBe(true)
expect(isValidDatePickType('dates')).toBe(true)
expect(isValidDatePickType('week')).toBe(true)
expect(isValidDatePickType('datetime')).toBe(true)
expect(isValidDatePickType('datetimerange')).toBe(true)
expect(isValidDatePickType('daterange')).toBe(true)
expect(isValidDatePickType('monthrange')).toBe(true)
expect(isValidDatePickType('moment')).toBe(false)
})
})