fix(v-model/emit): update:camelCase events should trigger kebab case equivalent
close #656
This commit is contained in:
parent
48152bc88e
commit
2837ce8428
@ -78,7 +78,9 @@ describe('renderer: component', () => {
|
|||||||
setup() {
|
setup() {
|
||||||
return () =>
|
return () =>
|
||||||
h(Child, {
|
h(Child, {
|
||||||
|
// emit triggering single handler
|
||||||
onBar: () => 1,
|
onBar: () => 1,
|
||||||
|
// emit triggering multiple handlers
|
||||||
onBaz: [() => Promise.resolve(2), () => Promise.resolve(3)]
|
onBaz: [() => Promise.resolve(2), () => Promise.resolve(3)]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -86,8 +88,32 @@ describe('renderer: component', () => {
|
|||||||
|
|
||||||
render(h(App), nodeOps.createElement('div'))
|
render(h(App), nodeOps.createElement('div'))
|
||||||
|
|
||||||
|
// assert return values from emit
|
||||||
expect(noMatchEmitResult).toMatchObject([])
|
expect(noMatchEmitResult).toMatchObject([])
|
||||||
expect(singleEmitResult).toMatchObject([1])
|
expect(singleEmitResult).toMatchObject([1])
|
||||||
expect(await Promise.all(multiEmitResult)).toMatchObject([2, 3])
|
expect(await Promise.all(multiEmitResult)).toMatchObject([2, 3])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// for v-model:foo-bar usage in DOM templates
|
||||||
|
test('emit update:xxx events should trigger kebab-case equivalent', () => {
|
||||||
|
const Child = defineComponent({
|
||||||
|
setup(_, { emit }) {
|
||||||
|
emit('update:fooBar', 1)
|
||||||
|
return () => h('div')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const handler = jest.fn()
|
||||||
|
const App = {
|
||||||
|
setup() {
|
||||||
|
return () =>
|
||||||
|
h(Child, {
|
||||||
|
'onUpdate:foo-bar': handler
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render(h(App), nodeOps.createElement('div'))
|
||||||
|
expect(handler).toHaveBeenCalled()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -25,7 +25,8 @@ import {
|
|||||||
NO,
|
NO,
|
||||||
makeMap,
|
makeMap,
|
||||||
isPromise,
|
isPromise,
|
||||||
isArray
|
isArray,
|
||||||
|
hyphenate
|
||||||
} from '@vue/shared'
|
} from '@vue/shared'
|
||||||
import { SuspenseBoundary } from './components/Suspense'
|
import { SuspenseBoundary } from './components/Suspense'
|
||||||
import { CompilerOptions } from '@vue/compiler-core'
|
import { CompilerOptions } from '@vue/compiler-core'
|
||||||
@ -221,7 +222,11 @@ export function defineComponentInstance(
|
|||||||
|
|
||||||
emit: (event, ...args): any[] => {
|
emit: (event, ...args): any[] => {
|
||||||
const props = instance.vnode.props || EMPTY_OBJ
|
const props = instance.vnode.props || EMPTY_OBJ
|
||||||
const handler = props[`on${event}`] || props[`on${capitalize(event)}`]
|
let handler = props[`on${event}`] || props[`on${capitalize(event)}`]
|
||||||
|
if (!handler && event.indexOf('update:') === 0) {
|
||||||
|
event = hyphenate(event)
|
||||||
|
handler = props[`on${event}`] || props[`on${capitalize(event)}`]
|
||||||
|
}
|
||||||
if (handler) {
|
if (handler) {
|
||||||
const res = callWithAsyncErrorHandling(
|
const res = callWithAsyncErrorHandling(
|
||||||
handler,
|
handler,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user