Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('it should support key modifiers and system modifiers', () => {
const el = document.createElement('div')
const fn = jest.fn()
// <div>
const nextValue = withKeys(withModifiers(fn, ['ctrl']), [
'esc',
'arrow-left'
])
patchEvent(el, 'keyup', null, nextValue, null)
triggerEvent(el, 'keyup', e => (e.key = 'a'))
expect(fn).not.toBeCalled()
triggerEvent(el, 'keyup', e => {
e.ctrlKey = false
e.key = 'esc'
})
expect(fn).not.toBeCalled()
triggerEvent(el, 'keyup', e => {
e.ctrlKey = true</div>
test('it should support "exact" modifier', () => {
const el = document.createElement('div')
// Case 1: <div>
const fn1 = jest.fn()
const next1 = withModifiers(fn1, ['exact'])
patchEvent(el, 'keyup', null, next1, null)
triggerEvent(el, 'keyup')
expect(fn1.mock.calls.length).toBe(1)
triggerEvent(el, 'keyup', e => (e.ctrlKey = true))
expect(fn1.mock.calls.length).toBe(1)
// Case 2: <div>
const fn2 = jest.fn()
const next2 = withKeys(withModifiers(fn2, ['ctrl', 'exact']), ['a'])
patchEvent(el, 'keyup', null, next2, null)
triggerEvent(el, 'keyup', e => (e.key = 'a'))
expect(fn2).not.toBeCalled()
triggerEvent(el, 'keyup', e => {
e.key = 'a'
e.ctrlKey = true
})
expect(fn2.mock.calls.length).toBe(1)
triggerEvent(el, 'keyup', e => {
// should not trigger if has other system modifiers
e.key = 'a'
e.ctrlKey = true
e.altKey = true
})
expect(fn2.mock.calls.length).toBe(1)
})</div></div>