mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-04 04:08:34 +08:00
9b23b1c9ec
Co-authored-by: 三咲智子 <sxzz@sxzz.moe>
22 lines
706 B
TypeScript
22 lines
706 B
TypeScript
import { nextTick, shallowRef } from 'vue'
|
|
import { describe, expect, it } from 'vitest'
|
|
import { useCursor } from '../use-cursor'
|
|
|
|
describe('useCursor', () => {
|
|
it('record and set cursor correctly', async () => {
|
|
const inputRef = shallowRef<HTMLInputElement>()
|
|
const [recordCursor, setCursor] = useCursor(inputRef)
|
|
if (inputRef.value == undefined) return
|
|
inputRef.value.value = 'abc'
|
|
//set a cursor position
|
|
inputRef.value.setSelectionRange(1, 1)
|
|
recordCursor()
|
|
inputRef.value.value = 'a-bc'
|
|
setCursor()
|
|
await nextTick()
|
|
const { selectionStart, selectionEnd } = inputRef.value
|
|
expect(selectionStart).toEqual(2)
|
|
expect(selectionEnd).toEqual(2)
|
|
})
|
|
})
|