test(runtime-dom): improve v-on system key modifiers test (#1597)
This commit is contained in:
parent
61b02d8577
commit
b8db7ab889
@ -41,35 +41,39 @@ describe('runtime-dom: v-on directive', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('it should support key modifiers and system modifiers', () => {
|
test('it should support key modifiers and system modifiers', () => {
|
||||||
const el = document.createElement('div')
|
const keyNames = ["ctrl","shift","meta","alt"]
|
||||||
const fn = jest.fn()
|
|
||||||
// <div @keyup.ctrl.esc="test"/>
|
|
||||||
const nextValue = withKeys(withModifiers(fn, ['ctrl']), [
|
|
||||||
'esc',
|
|
||||||
'arrow-left'
|
|
||||||
])
|
|
||||||
patchEvent(el, 'onKeyup', null, nextValue, null)
|
|
||||||
|
|
||||||
triggerEvent(el, 'keyup', e => (e.key = 'a'))
|
keyNames.forEach(keyName=>{
|
||||||
expect(fn).not.toBeCalled()
|
const el = document.createElement('div')
|
||||||
|
const fn = jest.fn()
|
||||||
|
// <div @keyup[keyName].esc="test"/>
|
||||||
|
const nextValue = withKeys(withModifiers(fn, [keyName]), [
|
||||||
|
'esc',
|
||||||
|
'arrow-left'
|
||||||
|
])
|
||||||
|
patchEvent(el, 'onKeyup', null, nextValue, null)
|
||||||
|
|
||||||
triggerEvent(el, 'keyup', e => {
|
triggerEvent(el, 'keyup', e => (e.key = 'a'))
|
||||||
e.ctrlKey = false
|
expect(fn).not.toBeCalled()
|
||||||
e.key = 'esc'
|
|
||||||
})
|
|
||||||
expect(fn).not.toBeCalled()
|
|
||||||
|
|
||||||
triggerEvent(el, 'keyup', e => {
|
triggerEvent(el, 'keyup', e => {
|
||||||
e.ctrlKey = true
|
e[`${keyName}Key`] = false
|
||||||
e.key = 'Escape'
|
e.key = 'esc'
|
||||||
})
|
})
|
||||||
expect(fn).toBeCalledTimes(1)
|
expect(fn).not.toBeCalled()
|
||||||
|
|
||||||
triggerEvent(el, 'keyup', e => {
|
triggerEvent(el, 'keyup', e => {
|
||||||
e.ctrlKey = true
|
e[`${keyName}Key`] = true
|
||||||
e.key = 'ArrowLeft'
|
e.key = 'Escape'
|
||||||
})
|
})
|
||||||
expect(fn).toBeCalledTimes(2)
|
expect(fn).toBeCalledTimes(1)
|
||||||
|
|
||||||
|
triggerEvent(el, 'keyup', e => {
|
||||||
|
e[`${keyName}Key`] = true
|
||||||
|
e.key = 'ArrowLeft'
|
||||||
|
})
|
||||||
|
expect(fn).toBeCalledTimes(2)
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
test('it should support "exact" modifier', () => {
|
test('it should support "exact" modifier', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user