mirror of
https://github.com/element-plus/element-plus.git
synced 2025-01-30 11:16:12 +08:00
feat(click-outside): return mousedown event (#2038)
* feat(click-outside): return mousedown event Return mousedown event for binding function. * feat(click-outside): expose both mouseup and mousedown event * feat(directives): add test cases for click-outside * feat(directives): clear the previously assigned event object
This commit is contained in:
parent
886f2a3075
commit
0bb128315b
@ -4,7 +4,15 @@ import ClickOutside from '../click-outside'
|
||||
const AXIOM = 'Rem is the best girl'
|
||||
const TRIGGER = 'trigger'
|
||||
const OTHER_CLASS = 'other-class'
|
||||
const handler = jest.fn()
|
||||
|
||||
// init some local variables
|
||||
let mousedownObject
|
||||
let mouseupObject
|
||||
// mock handler with implementations which makes assignment to the local variable that we registered above.
|
||||
const handler = jest.fn((eMouseup, eMousedown) => {
|
||||
mouseupObject = eMouseup
|
||||
mousedownObject = eMousedown
|
||||
})
|
||||
const Component = {
|
||||
template: `
|
||||
<div>
|
||||
@ -29,6 +37,10 @@ const _mount = () => mount(Component, {
|
||||
|
||||
describe('Directives.vue', () => {
|
||||
beforeEach(() => {
|
||||
// clear the previously assigned event object
|
||||
mousedownObject = null
|
||||
mouseupObject = null
|
||||
|
||||
handler.mockClear()
|
||||
})
|
||||
test('render test', () => {
|
||||
@ -47,11 +59,15 @@ describe('Directives.vue', () => {
|
||||
|
||||
const mousedown = document.createEvent('MouseEvents')
|
||||
mousedown.initMouseEvent('mousedown', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
|
||||
|
||||
document.dispatchEvent(mousedown)
|
||||
|
||||
const mouseup = document.createEvent('MouseEvents')
|
||||
mouseup.initMouseEvent('mouseup', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
|
||||
document.dispatchEvent(mouseup)
|
||||
expect(handler).toHaveBeenCalledTimes(1)
|
||||
|
||||
// here is the different part
|
||||
// we test the existence of the local variable.
|
||||
expect(mousedownObject).toBeDefined()
|
||||
expect(mouseupObject).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
@ -71,7 +71,7 @@ function createDocumentHandler(
|
||||
) {
|
||||
return
|
||||
}
|
||||
binding.value()
|
||||
binding.value(mouseup, mousedown)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user