element-plus/packages/hooks/__tests__/use-modal.vitest.ts
三咲智子 aaf90d99d0
test: switch to vitest (#5991)
* 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
2022-02-21 14:28:22 +08:00

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)
})
})