mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-05 04:37:47 +08:00
55348b30b6
* style: use prettier * style: just prettier format, no code changes * style: eslint fix object-shorthand, prefer-const * style: fix no-void * style: no-console
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { ref } from 'vue'
|
|
import { on, off } from '@element-plus/utils/dom'
|
|
import triggerEvent from '@element-plus/test-utils/trigger-event'
|
|
import usePreventGlobal from '../use-prevent-global'
|
|
|
|
describe('usePreventGlobal', () => {
|
|
const evtName = 'keydown'
|
|
const evt = jest.fn()
|
|
beforeAll(() => {
|
|
on(document.body, evtName, evt)
|
|
})
|
|
|
|
beforeEach(() => {
|
|
evt.mockClear()
|
|
})
|
|
|
|
afterAll(() => {
|
|
off(document.body, evtName, evt)
|
|
})
|
|
|
|
it('should prevent global event from happening', () => {
|
|
const visible = ref(true)
|
|
const evt2Trigger = jest.fn().mockReturnValue(true)
|
|
usePreventGlobal(visible, evtName, evt2Trigger)
|
|
|
|
triggerEvent(document.body, evtName)
|
|
|
|
expect(evt).not.toBeCalled()
|
|
expect(evt2Trigger).toHaveBeenCalled()
|
|
visible.value = false
|
|
// clean up
|
|
})
|
|
|
|
it('should not prevent global event from happening', () => {
|
|
const visible = ref(true)
|
|
const evt2Trigger = jest.fn().mockReturnValue(false)
|
|
usePreventGlobal(visible, evtName, evt2Trigger)
|
|
|
|
triggerEvent(document.body, evtName)
|
|
|
|
expect(evt).toHaveBeenCalled()
|
|
expect(evt2Trigger).toHaveBeenCalled()
|
|
|
|
visible.value = false
|
|
})
|
|
})
|