utils.test.ts
This file
Path
src/jsx/utils.test.ts
108 lines 路 2.8 KiB 路 TypeScript
Last changed by
Not known.
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109import { normalizeIntrinsicElementKey, styleObjectForEach } from './utils'
describe('normalizeIntrinsicElementKey', () => { test.each` key | expected ${'className'} | ${'class'} ${'htmlFor'} | ${'for'} ${'crossOrigin'} | ${'crossorigin'} ${'httpEquiv'} | ${'http-equiv'} ${'itemProp'} | ${'itemprop'} ${'fetchPriority'} | ${'fetchpriority'} ${'noModule'} | ${'nomodule'} ${'formAction'} | ${'formaction'} ${'href'} | ${'href'} `('should convert $key to $expected', ({ key, expected }) => { expect(normalizeIntrinsicElementKey(key)).toBe(expected) })})
describe('styleObjectForEach', () => { describe('Should output the number as it is, when a number type is passed', () => { test.each` property ${'animationIterationCount'} ${'aspectRatio'} ${'borderImageOutset'} ${'borderImageSlice'} ${'borderImageWidth'} ${'columnCount'} ${'columns'} ${'flex'} ${'flexGrow'} ${'flexPositive'} ${'flexShrink'} ${'flexNegative'} ${'flexOrder'} ${'gridArea'} ${'gridRow'} ${'gridRowEnd'} ${'gridRowSpan'} ${'gridRowStart'} ${'gridColumn'} ${'gridColumnEnd'} ${'gridColumnSpan'} ${'gridColumnStart'} ${'fontWeight'} ${'lineClamp'} ${'lineHeight'} ${'opacity'} ${'order'} ${'orphans'} ${'scale'} ${'tabSize'} ${'widows'} ${'zIndex'} ${'zoom'} ${'fillOpacity'} ${'floodOpacity'} ${'stopOpacity'} ${'strokeDasharray'} ${'strokeDashoffset'} ${'strokeMiterlimit'} ${'strokeOpacity'} ${'strokeWidth'} `('$property', ({ property }) => { const fn = vi.fn() styleObjectForEach({ [property]: 1 }, fn) expect(fn).toBeCalledWith( property.replace(/[A-Z]/g, (m: string) => `-${m.toLowerCase()}`), '1' ) }) }) describe('Should output with px suffix, when a number type is passed', () => { test.each` property ${'borderBottomWidth'} ${'borderLeftWidth'} ${'borderRightWidth'} ${'borderTopWidth'} ${'borderWidth'} ${'bottom'} ${'fontSize'} ${'height'} ${'left'} ${'margin'} ${'marginBottom'} ${'marginLeft'} ${'marginRight'} ${'marginTop'} ${'padding'} ${'paddingBottom'} ${'paddingLeft'} ${'paddingRight'} ${'paddingTop'} ${'right'} ${'top'} ${'width'} `('$property', ({ property }) => { const fn = vi.fn() styleObjectForEach({ [property]: 1 }, fn) expect(fn).toBeCalledWith( property.replace(/[A-Z]/g, (m: string) => `-${m.toLowerCase()}`), '1px' ) }) })})