mirror of
https://github.com/element-plus/element-plus.git
synced 2025-01-06 10:38:31 +08:00
aaf90d99d0
* test: use vitest * test: add script and ci * chore: improve tsconfig * refactor: use-form-item * fix: remove unused * chore: improve scripts * test: improve mock * refactor: change coverage
34 lines
800 B
TypeScript
34 lines
800 B
TypeScript
import { ref, nextTick } from 'vue'
|
|
import { describe, it, expect, fn } from 'vitest'
|
|
import { EVENT_CODE } from '@element-plus/constants'
|
|
import { useModal } from '../use-modal'
|
|
|
|
describe('useModal', () => {
|
|
it('should work when ref value changed', async () => {
|
|
const visible = ref(false)
|
|
const handleClose = fn()
|
|
|
|
useModal(
|
|
{
|
|
handleClose,
|
|
},
|
|
visible
|
|
)
|
|
|
|
expect(handleClose).not.toHaveBeenCalled()
|
|
|
|
visible.value = true
|
|
await nextTick()
|
|
const event = new KeyboardEvent('keydown', {
|
|
code: EVENT_CODE.esc,
|
|
})
|
|
document.dispatchEvent(event)
|
|
expect(handleClose).toHaveBeenCalledTimes(1)
|
|
|
|
visible.value = false
|
|
await nextTick()
|
|
document.dispatchEvent(event)
|
|
expect(handleClose).toHaveBeenCalledTimes(1)
|
|
})
|
|
})
|