Skip to content
Myr

utils.test.ts

This file

Path

src/validator/utils.test.ts

82 lines · 2.7 KiB · TypeScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than f0b094d point at it.

Merge commit from forkYusuke Wadabefore adoptionf0b094d

lines 1–82why, one step back
1import { expectTypeOf } from 'vitest'
2import type { InferInput, IsLiteralUnion } from './utils'34describe('IsLiteralUnion', () => {5 it('should return true for literal union types', () => {6 expectTypeOf<IsLiteralUnion<'asc' | 'desc', string>>().toEqualTypeOf<true>()7 })89 it('should return false for single literal', () => {10 expectTypeOf<IsLiteralUnion<'asc', string>>().toEqualTypeOf<false>()11 })1213 it('should return false for wide string type', () => {14 expectTypeOf<IsLiteralUnion<string, string>>().toEqualTypeOf<false>()15 })1617 it('should return true for literal union with undefined', () => {18 expectTypeOf<IsLiteralUnion<'asc' | 'desc' | undefined, string>>().toEqualTypeOf<true>()19 })20})2122describe('InferInput', () => {23 it('should preserve literal union types for query', () => {24 expectTypeOf<InferInput<{ orderBy: 'asc' | 'desc' }, 'query'>>().toEqualTypeOf<{25 orderBy: 'asc' | 'desc'26 }>()27 })2829 it('should convert string to string | string[] for query', () => {30 expectTypeOf<InferInput<{ page: string }, 'query'>>().toEqualTypeOf<{31 page: string | string[]32 }>()33 })3435 it('should convert number to string | string[] for query', () => {36 expectTypeOf<InferInput<{ page: number }, 'query'>>().toEqualTypeOf<{37 page: string | string[]38 }>()39 })4041 it('should preserve optional union (T | undefined) for query', () => {42 expectTypeOf<InferInput<{ name?: string | undefined }, 'query'>>().toEqualTypeOf<{43 name?: string | undefined44 }>()45 })4647 it('should preserve literal union with undefined for query', () => {48 expectTypeOf<InferInput<{ orderBy?: 'asc' | 'desc' | undefined }, 'query'>>().toEqualTypeOf<{49 orderBy?: 'asc' | 'desc' | undefined50 }>()51 })5253 it('should convert unknown to string | string[] for query (coerce support)', () => {54 expectTypeOf<InferInput<{ page: unknown }, 'query'>>().toEqualTypeOf<{55 page: string | string[]56 }>()57 })5859 it('should handle object | undefined for query (optional schema)', () => {60 expectTypeOf<InferInput<{ name?: string | undefined } | undefined, 'query'>>().toEqualTypeOf<61 { name?: string | undefined } | undefined62 >()63 })6465 it('should convert string to string for param', () => {66 expectTypeOf<InferInput<{ id: string }, 'param'>>().toEqualTypeOf<{67 id: string68 }>()69 })7071 it('should convert string to string for header', () => {72 expectTypeOf<InferInput<{ authorization: string }, 'header'>>().toEqualTypeOf<{73 authorization: string74 }>()75 })7677 it('should convert string to string for cookie', () => {78 expectTypeOf<InferInput<{ session: string }, 'cookie'>>().toEqualTypeOf<{79 session: string80 }>()81 })82})