Skip to content

Commit b8db7ab

Browse files
authored
test(runtime-dom): improve v-on system key modifiers test (#1597)
1 parent 61b02d8 commit b8db7ab

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

packages/runtime-dom/__tests__/directives/vOn.spec.ts

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,39 @@ describe('runtime-dom: v-on directive', () => {
4141
})
4242

4343
test('it should support key modifiers and system modifiers', () => {
44-
const el = document.createElement('div')
45-
const fn = jest.fn()
46-
// <div @keyup.ctrl.esc="test"/>
47-
const nextValue = withKeys(withModifiers(fn, ['ctrl']), [
48-
'esc',
49-
'arrow-left'
50-
])
51-
patchEvent(el, 'onKeyup', null, nextValue, null)
52-
53-
triggerEvent(el, 'keyup', e => (e.key = 'a'))
54-
expect(fn).not.toBeCalled()
55-
56-
triggerEvent(el, 'keyup', e => {
57-
e.ctrlKey = false
58-
e.key = 'esc'
59-
})
60-
expect(fn).not.toBeCalled()
44+
const keyNames = ["ctrl","shift","meta","alt"]
6145

62-
triggerEvent(el, 'keyup', e => {
63-
e.ctrlKey = true
64-
e.key = 'Escape'
65-
})
66-
expect(fn).toBeCalledTimes(1)
67-
68-
triggerEvent(el, 'keyup', e => {
69-
e.ctrlKey = true
70-
e.key = 'ArrowLeft'
71-
})
72-
expect(fn).toBeCalledTimes(2)
46+
keyNames.forEach(keyName=>{
47+
const el = document.createElement('div')
48+
const fn = jest.fn()
49+
// <div @keyup[keyName].esc="test"/>
50+
const nextValue = withKeys(withModifiers(fn, [keyName]), [
51+
'esc',
52+
'arrow-left'
53+
])
54+
patchEvent(el, 'onKeyup', null, nextValue, null)
55+
56+
triggerEvent(el, 'keyup', e => (e.key = 'a'))
57+
expect(fn).not.toBeCalled()
58+
59+
triggerEvent(el, 'keyup', e => {
60+
e[`${keyName}Key`] = false
61+
e.key = 'esc'
62+
})
63+
expect(fn).not.toBeCalled()
64+
65+
triggerEvent(el, 'keyup', e => {
66+
e[`${keyName}Key`] = true
67+
e.key = 'Escape'
68+
})
69+
expect(fn).toBeCalledTimes(1)
70+
71+
triggerEvent(el, 'keyup', e => {
72+
e[`${keyName}Key`] = true
73+
e.key = 'ArrowLeft'
74+
})
75+
expect(fn).toBeCalledTimes(2)
76+
});
7377
})
7478

7579
test('it should support "exact" modifier', () => {

0 commit comments

Comments
 (0)