test: fix runtime-dom v-on test

This commit is contained in:
Evan You 2020-04-07 11:41:48 -04:00
parent 2302dea162
commit f87d6b501e

View File

@ -22,9 +22,9 @@ describe('runtime-dom: v-on directive', () => {
const child = document.createElement('input') const child = document.createElement('input')
parent.appendChild(child) parent.appendChild(child)
const childNextValue = withModifiers(jest.fn(), ['prevent', 'stop']) const childNextValue = withModifiers(jest.fn(), ['prevent', 'stop'])
patchEvent(child, 'click', null, childNextValue, null) patchEvent(child, 'onClick', null, childNextValue, null)
const parentNextValue = jest.fn() const parentNextValue = jest.fn()
patchEvent(parent, 'click', null, parentNextValue, null) patchEvent(parent, 'onClick', null, parentNextValue, null)
expect(triggerEvent(child, 'click').defaultPrevented).toBe(true) expect(triggerEvent(child, 'click').defaultPrevented).toBe(true)
expect(parentNextValue).not.toBeCalled() expect(parentNextValue).not.toBeCalled()
}) })
@ -35,7 +35,7 @@ describe('runtime-dom: v-on directive', () => {
parent.appendChild(child) parent.appendChild(child)
const fn = jest.fn() const fn = jest.fn()
const handler = withModifiers(fn, ['self']) const handler = withModifiers(fn, ['self'])
patchEvent(parent, 'click', null, handler, null) patchEvent(parent, 'onClick', null, handler, null)
triggerEvent(child, 'click') triggerEvent(child, 'click')
expect(fn).not.toBeCalled() expect(fn).not.toBeCalled()
}) })
@ -48,7 +48,7 @@ describe('runtime-dom: v-on directive', () => {
'esc', 'esc',
'arrow-left' 'arrow-left'
]) ])
patchEvent(el, 'keyup', null, nextValue, null) patchEvent(el, 'onKeyup', null, nextValue, null)
triggerEvent(el, 'keyup', e => (e.key = 'a')) triggerEvent(el, 'keyup', e => (e.key = 'a'))
expect(fn).not.toBeCalled() expect(fn).not.toBeCalled()
@ -77,7 +77,7 @@ describe('runtime-dom: v-on directive', () => {
// Case 1: <div @keyup.exact="test"/> // Case 1: <div @keyup.exact="test"/>
const fn1 = jest.fn() const fn1 = jest.fn()
const next1 = withModifiers(fn1, ['exact']) const next1 = withModifiers(fn1, ['exact'])
patchEvent(el, 'keyup', null, next1, null) patchEvent(el, 'onKeyup', null, next1, null)
triggerEvent(el, 'keyup') triggerEvent(el, 'keyup')
expect(fn1.mock.calls.length).toBe(1) expect(fn1.mock.calls.length).toBe(1)
triggerEvent(el, 'keyup', e => (e.ctrlKey = true)) triggerEvent(el, 'keyup', e => (e.ctrlKey = true))
@ -85,7 +85,7 @@ describe('runtime-dom: v-on directive', () => {
// Case 2: <div @keyup.ctrl.a.exact="test"/> // Case 2: <div @keyup.ctrl.a.exact="test"/>
const fn2 = jest.fn() const fn2 = jest.fn()
const next2 = withKeys(withModifiers(fn2, ['ctrl', 'exact']), ['a']) const next2 = withKeys(withModifiers(fn2, ['ctrl', 'exact']), ['a'])
patchEvent(el, 'keyup', null, next2, null) patchEvent(el, 'onKeyup', null, next2, null)
triggerEvent(el, 'keyup', e => (e.key = 'a')) triggerEvent(el, 'keyup', e => (e.key = 'a'))
expect(fn2).not.toBeCalled() expect(fn2).not.toBeCalled()
triggerEvent(el, 'keyup', e => { triggerEvent(el, 'keyup', e => {
@ -109,7 +109,7 @@ describe('runtime-dom: v-on directive', () => {
const el = document.createElement('div') const el = document.createElement('div')
const fn = jest.fn() const fn = jest.fn()
const handler = withModifiers(fn, [button]) const handler = withModifiers(fn, [button])
patchEvent(el, 'mousedown', null, handler, null) patchEvent(el, 'onMousedown', null, handler, null)
buttons.filter(b => b !== button).forEach(button => { buttons.filter(b => b !== button).forEach(button => {
triggerEvent(el, 'mousedown', e => (e.button = buttonCodes[button])) triggerEvent(el, 'mousedown', e => (e.button = buttonCodes[button]))
}) })