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 "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)</div></div>
test('it should support "stop" and "prevent"', () => {
const parent = document.createElement('div')
const child = document.createElement('input')
parent.appendChild(child)
const childNextValue = withModifiers(jest.fn(), ['prevent', 'stop'])
patchEvent(child, 'click', null, childNextValue, null)
const parentNextValue = jest.fn()
patchEvent(parent, 'click', null, parentNextValue, null)
expect(triggerEvent(child, 'click').defaultPrevented).toBe(true)
expect(parentNextValue).not.toBeCalled()
})
test('it should support "self"', () => {
const parent = document.createElement('div')
const child = document.createElement('input')
parent.appendChild(child)
const fn = jest.fn()
const handler = withModifiers(fn, ['self'])
patchEvent(parent, 'click', null, handler, null)
triggerEvent(child, 'click')
expect(fn).not.toBeCalled()
})