Files
element-plus/packages/hooks/__tests__/use-calc-input-width.test.tsx
qiang d416dd74b0 feat(components): [input-tag] new component (#18885)
* feat(components): [input-tag] add input-tag component

* feat: styles

* test: add test

* docs: add docs

* docs: updata

* docs: uopdata

* docs: updata

* fix: optimize the style when input too long text

* feat: add draggable attribute

* fix: regain focus after dragged

* fix: regain focus on dragend

* refactor: useDragTag

* fix: style of disabled

* refactor: rename event name

* refactor: move useCalcInputWidth to hooks

* feat: add aria-label
2024-11-29 10:50:21 +08:00

46 lines
1.2 KiB
TypeScript

import { ref } from 'vue'
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import { useCalcInputWidth } from '../use-calc-input-width'
const AXIOM = 'Rem is the best girl'
describe('useCalcInputWidth', () => {
it('create', async () => {
const inputValue = ref()
const { calculatorRef, inputStyle } = useCalcInputWidth()
const wrapper = mount(() => (
<div
style={{
position: 'relative',
width: '100px',
}}
>
<input v-model={inputValue.value} style={inputStyle.value} />
<span
ref={calculatorRef}
aria-hidden="true"
v-text={inputValue.value}
style={{
position: 'absolute',
top: '0',
left: '0',
maxWidth: '100%',
visibility: 'hidden',
whiteSpace: 'pre',
overflow: 'hidden',
}}
/>
</div>
))
expect(wrapper.find('input').element.style.minWidth).toBe('11px')
await wrapper.find('input').trigger('focus')
await wrapper.find('input').setValue(AXIOM)
expect(inputValue.value).toBe(AXIOM)
expect(calculatorRef.value?.innerHTML).toBe(AXIOM)
})
})